We normally log in to a remote
SSH server using password authentication method. This is the most common authentication method for
SSH and is a good enough method for most people. Oftentimes though you might want to automatically log in to an
SSH server without having to enter your username and password combination.
This could just be a convenience factor for some, but is vitally important for those doing automation work. A script could be configured to automatically run commands on a remote server or for transferring files using
You can automatically log in to an
SSH server without entering username and password by using public key authentication method.
SSHkey pair on the local host if you don't already have one.
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/user/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user/.ssh/id_rsa. Your public key has been saved in /home/user/.ssh/id_rsa.pub. ##### snipped
Make sure to not set any passphrase for the key pair
$ sudo grep PubkeyAuthentication /etc/ssh/sshd_config [sudo] password for user: PubkeyAuthentication yes
Public key authentication is normally enabled by default.
SSHpublic key from local host to the
$ ssh-copy-id [email protected] /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 2 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]'s password: Number of key(s) added: 2 Now try logging into the machine, with: "ssh '[email protected]'" and check to make sure that only the key(s) you wanted were added.
|Red Hat Enterprise Linux|
|SUSE Linux Enterprise Server|
Comment anonymously. Login not required.