Login with SSH key
Puting your password every time when you login into a server via SSH can be tiresome, especially if your password is long. One way to make life easier and also safer is to use SSH keys.
- In the terminal of your local machine, type in
ssh-keygen. By default, the keys will be exported to
~/.ssh/id_rsa, using the default is okay in most cases, but if you have multiple keys want to avoid conflicts, you can change the destination. When it prompts you to enter a passphrase, you can just click Enter (empty passphrase) so that when you login to a server use this key pair, you don't need to input anything. But for better security, a passphrase is suggested.
- Copy your SSH public key into the server by
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]_address(change the path to the public key if you've saved it somewhere else). You'll be prompted to enter your password at the server.
- Log into the server by
ssh [email protected]_address. You should be able to login without having to enter your password! If it doesn't work, check the permission of the
~/.sshfolder on your server. Only you should have write access to it. You can change its permission from your home folder by
chmod 700 .ssh.