jump to navigation

SSH Public Key Based Authentication – Howto November 10, 2010

Posted by Tournas Dimitrios in Linux.
Tags:
trackback

If you would like to connect to your machine through ssh without being asked for a password you should do this.

  1. 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
  2. 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    user@192.168.1.xx:/home/user/.ssh/authorized_keys2      or ssh-copy-id -i  ~/.ssh/id_rsa.pub  username@example.com Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.
  3. 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 :

  1. Automated Login using the shell scripts.
  2. Making backups ( rsnapshot).
  3. Run commands from the shell prompt etc.

scp $HOME/.ssh/id_rsa.pub user@192.168.1.xx:/home/user/.ssh/authorized_keys2

### or

ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote-server

Comments»

1. The basics of rsync on Linux « Tournas Dimitrios - November 12, 2010

[…] will have the option to make this automatic using a cron job . Of course you have to enable the ssh login with no password first […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s