23 ms·
Stupid Unix Tricks
- raimue 7y agoRegarding the point of "SSH: Faster Crypto", you should not enforce only one single specific cipher for ssh. The reason also seems wrong, modern hardware should be capable of achieving better performance with an AEAD cipher (such as AES-GCM or ChaCha20-Poly1305) instead of AES-CTR, as the latter also requires an additional HMAC. 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.
- bhauer 7y ago> 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.
- TrueDuality 7y agoGenerally yes (there are a lot of SSH implementations out there), but that isn't the only thing you want to protect against: 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.
- deleted 7y ago[deleted]
- aasasd 7y agoI wonder if this issue is prone to cases of ‘a sysadmin writing a verbose config,’ like with TLS servers where ciphers are often put in a whitelist in my experience.
- nominated1 7y ago> Otherwise, you will miss out on better ciphers as they are added and would be stuck on this one forever. 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.
- xoa 7y ago>Otherwise, you will miss out on better ciphers as they are added and would be stuck on this one forever. 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?
- paulddraper 7y ago> what if we need to change this someday soon? Git was created in 2005 and its hash algorithm is already outdated. Additionally, software and hardware support continue to develop for better performance.
- CodesInChaos 7y agoSHA-1 was already broken (Feb 2005) when git was first published (April 2005). But Linus decided that git doesn't need a collision resistant hash function. https://marc.info/?l=git&m=115678778717621 https://marc.info/?l=git&m=115678778717621
- paulddraper 7y agoSHA-1 was not broken until 2017. http://shattered.io/ http://shattered.io/ 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.
- roryrjb 7y agoBefore we begin, first note that bashrc refers to something that runs in each and every new shell, and profile refers to something that runs only in interactive shells (used by a user at a keyboard, not just a shell script, for example). They aren’t the same and you don’t want them to be the same. 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.
- robohoe 7y ago.bashrc would get executed when you run something in cron. Cron runs non-interactive shell sessions.
- deleted 7y ago[deleted]
- roryrjb 7y agoI tested this and this is not the case. My .bashrc does a lot of things such as custom completions that are expensive that I would not want run by anything else other than an interactive shell. It also has return at the end so if anything I don't know about adds stuff to it, it won't get executed. This would break other scripts loading .bashrc as well. So as far as I can see this is false.
- tremon 7y agoFrom the manual: 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.
- benburleson 7y agoWell, I had to stop reading when I scrolled a bit and some pop up blocked the content with (I presume) the button to close it off screen on mobile.
- frogpelt 7y agoThere should have been an X at the top right corner. Also, do you have reader mode on your device? That would fix it too.
- deadbunny 7y agoOr you know, people could not put popovers on blogs.
- sneak 7y agoWith the advent of RSS going by the wayside, email has become the sole reliable method of doing non-invasive push notifications. 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.
- ilammy 7y agoI don’t really remember popups ‘please add our feed to your RSS reader’, instead there was a link to add the feed which took exactly enough screen space.
- lawnchair_larry 7y agoIt was terrible advice.
- TheRealPomax 7y agoIf you're not browsing with an adblocker installed, then this complaint is basically moot: it's 2019, the ad-free internet died years ago; use a decent adblocker. If they show up even with that active, though, now you have a valid complaint.
- jzzskijj 7y agoThis got me to raise an eyebrow: 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.
- enriquto 7y agoTrue! Also the mixing of upper and lower-case directories on ~ is a red flag. 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 &&)
- toxik 7y agoA "red flag" for what? He's using macOS, in which the typical user-facing directories are propercase (/Users, ~/Documents, etc.)
- enriquto 7y agoI don't know, it's just very ugly and it lacks a sense of aesthetics (just like everything else on macos, so at least it is consistent). It's like reading a book that uses three different fonts on each page. You just cannot take it seriously.
- shrimp_emoji 7y agoletter cases were a mistake in language itself. cool way to bloat your glyph set to double the size and introduce aesthetic and string matching problems.
- laumars 7y agoRelated fact: the term "case" dates back to the old printing presses where characters would be individual blocks or wood or metal and they were stored in draws. Capital letters were stored in the draw above non-capital letters -- hence why they are referred to as "upper case" and "lower case". 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.
- nat 7y agoIs there any advantage/difference to using ProxyCommand with netcat vs just saying "ProxyJump bastion.example.com"?
- termie 7y agoProxyJump was added in OpenSSH 7.3 so systems from a few years ago might not support it. It does the same thing as ProxyCommand with -W %h:%p but you can’t set custom options for the jump connection with ProxyJump.
- deleted 7y ago[deleted]
- blfr 7y agoThe best way to store SSH private keys is in a hardware security module, or HSM. I have three Yubikeys. Would I need to add three ssh keys to every one of my ssh accounts?
- xenophonf 7y agoYes. If one Yubikey were lost, stolen, or damaged, you would then revoke its access by removing the corresponding entry in ~/.ssh/authorized_keys.
- eaguyhn 7y agoThere are sites that show how to move your key to multiple Yubikeys. (Basically, backup your keyring before moving to Yubikey, then restore and repeat move to a new Yubikey). This is the guide I followed: https://github.com/drduh/YubiKey-Guide https://github.com/drduh/YubiKey-Guide
- sneak 7y agoYou can load keys into yubikeys if you like (and thus load the same key into multiple devices), but I choose to generate unique keys on-device, so each one has its own (which would make the answer to your question “yes”). 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.
- jolmg 7y agoUnless you put the same OpenPGP key on all of them, or you want them to have a different levels of access.
- bregma 7y agoBash is not Unix.
- jacobush 7y agoNo, because Bash is GNU is Not Unix.
- kps 7y agoEmbrace, extend, extinguish. GNU has stage three well under way.
- wglb 7y agoBut it does run on my Unix boxes.
- yjftsjthsd-h 7y agoAlthough amusingly, not exclusively; it also runs on Haiku and NT. (This isn't at all to say that it doesn't fit in an article about Unix, since it's very popular there (just like talking about Firefox on Unix wouldn't be out of place), just a fun side note.)
- waddlesplash 7y agoHaiku is a UNIX, though. :)
- teekert 7y ago"Docker desktop for mac is closed source software, which is dumb for something that asks for administrator permissions on your local machine. This lameness aside, it runs the docker daemon..." ...Proceeds to run MacOS...
- jacobush 7y agoSure, but there are probably more eyes on MacOS releases than on Docker releases.
- deleted 7y ago[deleted]
- TheRealPomax 7y agoLike every time someone points this out: there are an unreasonable amount of companies that don't let you pick anything else. It's either a macbook, or a macbook, and if you want a different machine go buy it yourself and use it outside of work hours "because we can't afford writing three different copies of the same internal documentation for more than one OS when we're the ones paying for the machine you work on". 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".
- majewsky 7y ago> Installing [Docker] on linux [...] 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.
- as1mov 7y ago> Installing it on linux or windows is an exercise ...? 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-install-and-use-docker-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-inst...
- asaph 7y ago> Don’t try to install things with brew if brew is not installed: 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.
- deleted 7y ago[deleted]
- majewsky 7y agoI think this snippet needs some context. In all contexts that I can imagine, the first line should actually be if which jq &>/dev/null; then brew install jq fi
- playpause 7y agoThat seems more reasonable, but it's not what the author wrote. He precedes the snippet with "Don’t try to install things with brew if brew is not installed", so his intention does seem to be to swallow errors silently, which is definitely weird.
- visualphoenix 7y agoauthor should probably be using: command -v instead of: which
- frou_dh 7y agoFighting the good(?) fight for POSIX shell portability. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c... https://shellhaters.org https://shellhaters.org
- oweiler 7y agoInstead of which it's better to use command -v.
- derefr 7y agoThis inspired me to (quickly) write down my own Stupid Bash Tricks: https://gist.io/@tsutsu/2c11fc0a36000a46566e9fd62c60dea4 https://gist.io/@tsutsu/2c11fc0a36000a46566e9fd62c60dea4 Most of it might be somewhat obvious; but scroll down to "Bash Hooks" for a cool trick I've never seen anywhere else.
- Falcorian 7y agoI found the OSX specific XDG section helpful, because I've been setting it to ~/.cache for years! Good to know there is a better way that the OS understands (a bit a least).
- deleted 7y ago[deleted]
- saulrh 7y agoUsing a tor hidden service for emergency ssh access is pretty sweet and I'm going to have to go set that up for myself now. Maybe with an extra bit to auto-publish the hostname so I don't have to write it down every time something changes.
- 11235813213455 7y agoWith docker >= 18.09, you can connect directly over SSH by setting DOCKER_HOST=ssh://<user>@<host>
- lilyball 7y agoI've had my shell startup scripts modularized for many years now, but I do a much more complicated system where the scripts actually have a function `require` exposed to them that can be used to express dependencies. If you `require` something that's already been loaded it does nothing, so each script is still only just loaded once.
- kerng 7y agoSsh ProxyCommand: make sure to use ssh -W option rather then depending on netcat.
- saagarjha 7y ago> I use Mac OS X (pron: “ten”). To be extra pedantic: unless you’re running an eight-year-old OS, you are likely running either OS X or macOS.
- jlbang 7y agoThank you!
- wyclif 7y agoHis tip about running "make clean" on ~/Desktop is okay, assuming people actually use Desktop the way he does. Which I observe that many, possibly most, users don't. Apple says that "The desktop is where you do most of your work", but I see a lot of desktops with no files whatsoever. https://support.apple.com/en-gb/guide/mac-help/mh40612/mac https://support.apple.com/en-gb/guide/mac-help/mh40612/mac
- pololee 7y agoVery true because I don't want any file icons on my wallpaper. Btw, i use this https://irvue.tumblr.com/ https://irvue.tumblr.com/
- yoloClin 7y agoThe author configures lots of syncing by setting the location of config files, I do it by setting up a whitelist based gitignore in my homedir: * !.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.
- Noumenon72 7y agoSo you have a gitignore that says "ignore everything except these three files" -- what does that do? Is it supposed to replace the line where he curls those files to github? Isn't it awkward having all your other git repos in your home dir be under that git repo?
- yoloClin 7y ago> what does that do? Is it supposed to replace the line where he curls those files to github 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 :)
- m463 7y agoanother interesting site is: https://dotfiles.github.io/ https://dotfiles.github.io/
- chsitter 7y agoThanks for the cached ssh connections thing, didn't know that was possible. Not that useful when I'm on my environment with TMUX (typically have each connection in its own tmux pane) but massively useful on all the jump boxes where I don't have a sensible shell environment :)
- rhabarba 7y agoI find it weird that an article about "Unix tricks" requires the GNU bash shell.
- esjeon 7y agoI was expecting something like cat file | less Stop abusing cats!
- donalhunt 7y ago> "always ssh as root" example urggh... 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.