SSH tips
Following are some tips to help remind myself how to perform SSH tasks that I do less frequently.
Passwordless SSH login §
Passwordless SSH login is when you run ssh user@server
, and are automatically logged in without being prompted for a password.
There are essentially just two steps for setting up passwordless SSH login:
- Generate a key.
- Install the key on the relevant server(s).
Generate the key §
Simply run:
When prompted for a passphrase, just press enter.
If you do enter a passphrase, you will be prompted for that passphrase when you try to log in to a server with your key.
Install the key (automatically) §
Simply run:
This will install your key to the specified server
. You will be prompted for a password (but hopefully this will be the last time!).
Install the key (manually) §
On some systems, the ssh-copy-id
script may not exist. For example, on Windows 10. Fortunately, the script itself is fairly simple, so you can manually perform it by doing the following:
Install the key (manually, via Cygwin) §
Same as above, but if using Cygwin it may be necessary to use quotes to handle the Windows path, e.g.:
Install the key (manually, on a different port) §
Same as above, but if not using port 22, you can specify the port using the -P
option:
Note that the position of -P
is important. It must come before the file argument else a No such file or directory
error will occur as the port is misinterpreted as an additional file:
Similarly, don’t let your ssh muscle memory trick you! Using -p
(rather than -P
) actually means “preserve modification times, access times, and modes”. As such, the command is valid, but won’t do what you want:
SSH tunneling §
Can SSH tunnel through a gateway:
Can do SSH tunnels to multiple ports/hosts in one go: