You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to prepare a server for public key authentication
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
ssh-copy-id <server-address>
ssh-copy-id throws an error if ~/.ssh/authorized_keys does not exist. Alternatively, you can do the following two steps.
Transfer id_rsa.pub to the server in your favorite way.
cat id_rsa.pub >> ~/.ssh/authorized_keys
~/.ssh/authorized_keys
is a list of public keys that are allowed to be used for SSH connections.
ssh_config
Precedence
ssh -F 'my_ssh_config.txt'
~/.ssh/config
/etc/ssh/ssh_config
Content
User <username>
Host MyHost1
HostName www.example.com
User user1
Host MyHost2
HostName www.foobar.com
User user2
Why use an SSH key passphrase in ssh-keygen
Without a passphrase, if someone gains access to your computer, he also gains access to every system that uses SSH key.
What is a public key fingerprint (aka an SSH key fingerprint)
An SSH key fingerprints is a hash produced by applying a cryptographic hash function such as SHA-2 to an SSH key.
Why use a public key fingerprint (aka an SSH key fingerprint)
Lets you confirm that a server you are trying to connect to is not an impersonator in a man-in-the-middle attack.
SSH servers release their public key fingerprints and SSH clients store those public key fingerprints with each server's hostname and IP address in ~/.ssh/known_hosts.
Port forwarding
Local port forwarding
Lets you bypass a company firewall that blocks Wikipedia.
# Connect to port X on SSH client -> (SSH tunnel) -> SSH server -> Port Y on SSH server
ssh -L <Port X>:localhost:<Port Y><SSH server># Connect to port X on SSH client -> (SSH tunnel) -> SSH server -> Port Y on destination server
ssh -L <Port X>:<Destination server>:<Port Y><SSH server>
Remote port forwarding
Lets you connect from your SSH server to a computer on your company's intranet.
# Connect to port X on SSH server -> (SSH tunnel) -> SSH client -> Port Y on SSH client
ssh -R <Port X>:<localhost>:<Port Y><SSH server># Connect to port X on SSH server -> (SSH tunnel) -> SSH client -> Port Y on destination server
ssh -R <Port X>:<Destination server>:<Port Y><SSH server>
Note
Port forwarding can be disabled as follows in ~/.ssh/config of an SSH server.