Stupid Unix Tricks
sneak.berlin
sneak.berlin
If there really is a slow (or insecure) cipher you do not want to use, remove it by prepending a minus sign, for example `Ciphers -3des-cbc`, which keeps all other default ciphers. Otherwise, you will miss out on better ciphers as they are added and would be stuck on this one forever.
That sounds like good advice; thank you. Out of curiosity, as someone who is fairly noobish on SSH, are "better ciphers" typically automatically preferred by SSH clients and servers as they are introduced? In other words, do the SSH implementations maintain a rank ordering that prefers "better" ciphers? That would be my expectation, but it seems I am often surprised by the bad defaults when dealing with security.
1. If there is a critically broken cipher an attacker that can perform a MiTM attack and claim it only supports the broken cipher between both ends which can force an association using that and thus break your crypto transparently.
This type of attack would be high effort and targeted. Most threat models don't really need to address this issue, but disabling ciphers is so easy you mind as well spend a couple of keystrokes doing it.
2. If the cipher implementation is broken (think OpenSSL's heartbleed) then leaving the cipher available opens you up to being directly attacked by botnets.
This type of attack has a high initial cost for the attacker (developing the exploit) but can be sprayed across the entire internet. This is the type of attack that would affect most people and should be protected against by patching and disabling known bad ciphers.
You’ve identified issues with whitelisting but blacklisting isn’t perfect either. For example, many don’t trust NIST and may want to prevent the use of any of their future curves. Blacklisting fails here.
When updating to a newer version of SSH I think it’s good practice to ‘man ssh_config’ and at least look at KexAlgorithms, HostKeyAlgorithms and Ciphers.
Is that actually a real concern at this point vs the risk that comes from not white listing a few known reliable ones? It seems like old-style security, favoring modularity and "what if we need to change this someday soon?", but in practice it's turned out to be a lot less valuable than expected and raise significant risks of accidentally using something bad. We seem to be past the point where new ciphers being "better" is actually an event to be expected with any real frequency, prime/elliptic curve seems pretty mature now. Post-quantum could be a new frontier at some point, but may well require significant other changes as well.
WireGuard for example decided to just flat out say that any cipher changes will be tightly coupled with a full on version change. If you're using it you know exactly what you're getting and that's it.
I don't disagree that white listing means care with what is chosen, and picking AEAD-based seems like a better idea anyway (WG is Curve25519/ChaCha20-Poly1305/SipHash/BLAKE2s). Plus there is server compatibility to consider in some cases. But I'm not sure the logic of "you might miss out on better ciphers as they are added" is convincing either, vs setting yourself an alarm to recheck your SSH setup every year or two. Shouldn't any cipher additions/deletions arguably be something you actively consider, rather than have automagically added?
Git was created in 2005 and its hash algorithm is already outdated.
Additionally, software and hardware support continue to develop for better performance.
If you know an earlier instance, go ahead and take the crown from the shattered folks.
---
The choice to use SHA-1 was a trade-off of security, size, performance. If Linux invented git today, I imagine the choice would have been different, because those parameters are now different.
The time between a theoretical attack and practical demonstration of an attack should be considered a grace period we can use to migrate to a secure primitive. Choosing SHA-1 for an application which relies on collision resistance after the 2005 papers is plain incompetence.
Git chose SHA-1 because Linus did not consider collisions a problem. The downsides of SHA-256 were pretty small even then (32 instead of 20 bytes, and somewhat slower performance which is still faster than most IO).
At moments like that, you want an easy and fast way to disable such a cipher, but stay interoperable otherwise.
if which brew 2>&1 /dev/null ; then
brew install jq
fi
This just hides a useful error message (brew not installed). I would rather just see that error message (either interactively or in a log) and have the script fail. Hiding the error message just leads to an eventual failure down the road when jq is invoked. if which jq &>/dev/null; then
brew install jq
fi command -v brew >/dev/null && brew install jq hash foo &>/dev/null || { echo "foo command not found blabla..." >&2; exit 1; }
more info:
https://stackoverflow.com/questions/592620/how-to-check-if-a...command: command [-pVv] command [arg ...] Execute a simple command or display information about commands.
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
Options:
-p use a default value for PATH that is guaranteed to find all of
the standard utilities
-v print a description of COMMAND similar to the `type' builtin
-V print a more verbose description of each COMMAND
Exit Status:
Returns exit status of COMMAND, or failure if COMMAND is not found.I never knew about help to describe a builtin shell command. normally searching for something like "command" in the bash man page would be very tedious.
also: help echo
`which ls` and `help ls` will show you, if it is similar on your system.
"man echo" on linux describes /usr/bin/echo "help echo" describes the builtin.
on the othe hand, "man command" on mac os x gives a huge manpage of builtins (still hard to search for the common word "command")
test (type brew 2>/dev/null); and brew # blahblah type -p brew >/dev/null ^&1; and brew
in Bash it would be: type -p brew &>/dev/null && brew
Using test avoids caring about stdout/stderr. if which brew >/dev/null 2>&1 ; then
brew install jq
fi
Which would hide the error message. The code you posted outputs: brew not found
/dev/null not foundWith a proper dependency graph, the tasks installing things would depend on the task `brew-installed`.
This, of course, is leaving alone the point that installing stuff on startup is weird, doubly so with brew which is pretty slow.
I'm not an expert on bash exactly though I am a heavy shell user (POSIX shell for scripting) but this part doesn't sound right. When is .bashrc ever executed when bash isn't interactive? And as far as I can tell when I open new shells .profile isn't read. I am using Linux and tmux and the reason I mention tmux is that it opens bash as a login shell and therefore .bash_profile is also loaded. Is this a mac OS thing or the version of bash mac OS comes with, which I believe is really old due to some license issues.
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option.
So interactive, non-login shells only.
But also:
When invoked as an interactive shell with the name sh , bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. [A] shell invoked as sh does not attempt to read and execute commands from any other startup files
So only when invoked as bash, not as sh.
On a Mac you usually end up adding
if [ -f ~/.bashrc ]; then
. ~/.bashrc;
fi
To your .profile or .bash_profile.Just read that part and now I can’t help but question the rest of it before even reading it
Apple breaks it, but there is.
Here’s info, https://unix.stackexchange.com/questions/170493/login-non-lo...
ZSH follows the same for login/non-login but I don’t see it for interactive.
if [ -n "$PS1" ] ; then
[ -r ~/.bashrc ] && . ~/.bashrc
[ -r ~/.bash_login ] && . ~/.bash_login
fiTrue, iff you have a .bash_profile. Bash only reads the first of ~/.bash_profile, ~/.bash_login, ~/.profile. It will ignore the rest of the list once it's found an existing file.
Note that in macOS every new Terminal (tab) opens a login shell, while most GUI Linux environments don't. (In Tmux/screen it depends on the configuration).
> When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
> When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc
So, this is wrong:
> bashrc refers to something that runs in each and every new shell
Because .bashrc doesn't run when you execute a shell script, and doesn't run when you use `bash -c`.
And this is wrong:
> profile refers to something that runs only in interactive shells
Because it does run in non-interactive shells when they're login shells, and because it implies that it runs in every interactive shell, which it doesn't. It only runs in login shells.
Never.
TFA has got it wrong.
24435 bash 3 0 /etc/profile
24435 bash 3 0 /etc/profile.d/
24435 bash 3 0 /etc/profile.d/256term.sh
24435 bash 3 0 /etc/profile.d/colorgrep.sh
24435 bash 3 0 /etc/profile.d/colorls.sh
24435 bash 3 0 /etc/profile.d/lang.sh
24435 bash 3 0 /etc/profile.d/less.sh
24435 bash 3 0 /etc/profile.d/which2.sh
24435 bash 3 0 /etc/profile.d/sh.local
24435 bash 3 0 /home/centos/.bash_profile
24435 bash 3 0 /home/centos/.bashrc
24435 bash 3 0 /etc/bashrc
24736 bash 3 0 /home/centos/.bashrc
24736 bash 3 0 /etc/bashrc
24736 bash 3 0 /etc/profile.d/
24736 bash 3 0 /etc/profile.d/256term.sh
24736 bash 3 0 /etc/profile.d/colorgrep.sh
24736 bash 3 0 /etc/profile.d/colorls.sh
24736 bash 3 0 /etc/profile.d/lang.sh
24736 bash 3 0 /etc/profile.d/less.sh
24736 bash 3 0 /etc/profile.d/which2.sh
[1] http://www.brendangregg.com/blog/2014-07-25/opensnoop-for-li...So your capture here doesn't show only the files that bash itself decided to load. You also won't see the fallback files (e.g. bash will open .profile if .bash_profile doesn't exist).
https://blog.flowblok.id.au/2013-02/shell-startup-scripts.ht...
Most of it might be somewhat obvious; but scroll down to "Bash Hooks" for a cool trick I've never seen anywhere else.
if [[ -d "$HOME/dev/go" ]]; then
export GOPATH="$HOME/dev/go"
fi
Using a directory named "dev" not to store device files, but development tools. I am so stuck with conventions.Offtopic, but this kind of one-line conditions are typically best written as
test -d ~/dev/go && export GOPATH=~/dev/go
then it is easier tho change the sign of the condition (by using either || or &&)It's like reading a book that uses three different fonts on each page. You just cannot take it seriously.
cool way to bloat your glyph set to double the size and introduce aesthetic and string matching problems.
In terms of your general point, upper and lower case letters were originally different stylistic type-faces rather than "modes" of a letter in the same type-face. It wasn't until relatively recently in our writing history that the rules of capital letters became defined rather than a style choice and I'm certain they weren't thinking much about the problems that might cause with string matching on digital systems invented several hundred years later.
MacOS is one of the few registered UNIX systems out there (https://en.wikipedia.org/wiki/Single_UNIX_Specification#macO...).
I actually do not own a Mac, but it is a decent OS and performs well and tries to be windows friendly (hence camelcase and spaces) and tries to be stable and secure.
I opt for the if-brackets rather than the one line syntax because it is clearer to read. “if this, then that” is less mental effort than remembering just how boolean operators short circuit, for me at least. It's a few extra lines but I prefer the layout, indent, and ease of scanning.
Not all of them. You can choose to have a case-sensitive filesystem if you’d like.
Holy smacks, all these years and I never knew that! Too bad auto-complete doesn't pick up on it though.
In 1990's I used to have ~/dev in school's Sparcs running SunOS, as I needed some device files that weren't available in /dev. But I was able to mknod them.
I've been also toying with chroots quite a lot and there dev is also quite essential for its original purpose. Therefore "dev" is like a reserved keyword for me in *nix systems.
Personally I use ~/w (like "work") or ~/code mostly. I've had ~/dev once for storing projects, but I had to rename it as it was distracting (to me) :)
Neither do I.
My problem is finding an alternative to "dev" that is just as convenient. Do any of you have any suggested alternatives?
Most everything I do development-wise is in Git, which is why I came to that name years ago.
I also have a "~/tmp" directory for one-off dev stuff that I clean up periodically.
...but not in the "operator" sense. Rather, the "operations" sense...and that is because i used to use ~/projects...But i got lazy to type that out.
But I must admit that `~/code` seems a good alternative to me.
And in an unfortunate twist, if you _have_ to run Docker, macos is actually the best choice for that. Installing it on linux or windows is an exercise in "you know what, maybe I should buy a mac for this instead".
This quip is outdated. Installing Docker on Linux is only a hassle if you're using ancient distributions like Debian or RHEL from 5-10 years ago. Anything released after about 2016 should have no problems at all running Docker, and probably comes with Docker in the default repos.
...? Am I missing something obvious? Installing docker on Ubuntu is as simple as
sudo apt install docker.io
and you're done. Installing from the official repos is simple too if you want the latest version [1][1] https://www.digitalocean.com/community/tutorials/how-to-inst...
You are aware that Docker is a Linux technology right?
As others have pointed out it is trivial to install on Linux compared to Windows or Mac.
I get it that Mac folks like their Macs, and I will argue your case at work, but please stop the misinformation campaign.
Mac is different than Windows and Linux. Not generally better.
It is better than Linux for running Adobe software.
It is horrible for running gimp.
It cannot run Docker natively but it might have a number of other advantages.
Source: I once used a Mac. Started with great enthusiasm, gave up three years later, massively disappointed. Liter realized Mac actually is the best computer that exists for Mac users, but not for me and many others.
Docker for Mac is a mess, it regularly pegs CPUs for no obvious reason at all on idling containers among other things. Plus now it packages k8s which made it balloon in size.
*
!.gitignore
!.bashrc
!.ssh/authorized_keys
It's fast (comparative to a blacklist based 'git status' scan) and less work :)On a sidenote, I'm curious about the security implications of the git repository - if the git host the service is breached, as far as I known there's really nothing stopping the actor leveraging access to achieve code execution on my host right?
I'm aware of commit signing but in the context of a raw git directory synced over ssh an attacker could create and use any valid signature key to commit to the repo. Hosting on Gitlab/Github would require a breach or significant abuse of security controls, but is still possible, too.
No, it is for synchronization. See the article sections titled 'SSH: Move Your SSH Config File Into a Synced Folder' and 'Extra Credit'.
> So you have a gitignore that says "ignore everything except these three files" -- what does that do?
My gitignore is upwards of 100 files, but allows me to track changes and synchronize configurations across hosts, which I do often as I often work in short-lived graphical VMs and across multiple hosts. Using a whitelist of tracked files means 'git status' wont take seconds/minutes to scan the entire directory tree under my homedir which seemed to be the case when using a blacklist when I initially configured it.
> Isn't it awkward having all your other git repos in your home dir be under that git repo?
It breaks stuff like `git add -A` which I haven't fully solved, but don't really feel the need to - most of my commits are 2-3 files at most and I'd prefer to be aware of exactly what's being committed for the additional minor overhead.
There's other alternatives, like rsync, which solve entire tree synchronization but that's not what I'd normally like to do as my ultraportable has a 128gb SSD and my daily driver is a 2TB laptop. I'd be open to hear other suggestions, but at this point git is a convenient and flexible solution that works well in my environment :)
*
!*/
!.gitignore
!.bashrc
!.ssh/authorized_keysTo be extra pedantic: unless you’re running an eight-year-old OS, you are likely running either OS X or macOS.
instead of: which
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...
defaults write com.apple.finder CreateDesktop falseurggh... I've seen devs do this too many times and it breaks a bunch of stuff when configured incorrectly. You almost never want "Host *" to have a user entry.
also completely ignores the "don't ssh as root" opsec best practice. I would strongly argue that even for dev environments, it's worthwhile building the opsec muscle memory and spending the effort at the start of a project.
I have three Yubikeys. Would I need to add three ssh keys to every one of my ssh accounts?
If one Yubikey were lost, stolen, or damaged, you would then revoke its access by removing the corresponding entry in ~/.ssh/authorized_keys.
This is the guide I followed: https://github.com/drduh/YubiKey-Guide
One upside though is that all your keys can go as individual lines in authorized_keys, so there is still only one file to install on remote machines.
cat file | less
Stop abusing cats!Also, do you have reader mode on your device? That would fix it too.
I wish it weren’t so, but collecting emails was the personal advice of someone highly regarded by both myself and HN so it’s what I do—with an apology in the modal itself.
If they show up even with that active, though, now you have a valid complaint.
Good taste hasn't died and never will.
And there was never effectively an “ad-free internet”, if by internet you mean Web. We had ads on the Web in 1994.