SSH Public Key Based Authentication – Howto November 10, 2010Posted by Tournas Dimitrios in Linux.
If you would like to connect to your machine through ssh without being asked for a password you should do this.
- Create a public/private key pair: ssh-keygen -t rsa Please Do not forget not to write any passphrase, just empty for no passphrase for this to work
- Copy te file id_rsa.pub to the $HOME/.ssh directory of the machine you wish to connect to, where $HOME is the directory of the user you would like to connect as. /root/.ssh in the case you would like to connect as root. Consider you would like to connect as the user user scp $HOME/.ssh/id_rsa.pub email@example.com:/home/user/.ssh/authorized_keys2 or ssh-copy-id -i ~/.ssh/id_rsa.pub firstname.lastname@example.org Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.
- Now you can connect to the remote server without being asked for a password. ssh -l username 192.168.1.xx
As you see the connection on a remote ssh server can be done in non-interactive mode , so it can be used for :
- Automated Login using the shell scripts.
- Making backups ( rsnapshot).
- Run commands from the shell prompt etc.
scp $HOME/.ssh/id_rsa.pub email@example.com:/home/user/.ssh/authorized_keys2
ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote-server