1. Login as the user that you want to setup the ssh keys, in this case we are using user test1.
2. Create a private and public key:
[test1@server4 ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/test1/.ssh/id_rsa): Created directory '/home/test1/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/test1/.ssh/id_rsa. Your public key has been saved in /home/test1/.ssh/id_rsa.pub. The key fingerprint is:test1@server4.oracle.com The key's randomart image is: +--[ RSA 2048]----+ | .o... oo.| | . . .Eooo| | o . oo+.| | . + ...+.| | S o *| | *o| | =| | .| | | +-----------------+ [test1@server4 ~]$
Note:
You can specify an option on the ssh-keygen like the size and the type. More information on the man ssh-keygen
-b bits – Specifies the number of bits in the key to create. For RSA keys, the minimum size is 768 bits and the default is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS186-2.
3. Move to you .ssh directory were the key was created and list the files in the directory:
[test1@server4 ~]$ cd .ssh [test1@server4 .ssh]$ ls id_rsa id_rsa.pub
4. Copy the public key to the target server (server3):
[test1@server4 .ssh]$ ssh-copy-id -i id_rsa.pub test1@server3 The authenticity of host 'server3 ([ip])' can't be established. RSA key fingerprint is [RSA_KEY]. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'server3,[ip]' (RSA) to the list of known hosts. test1@server3's password:
5. Now try logging into the machine, with “ssh ‘test1@server3′”, and check in:
.ssh/authorized_keys
to make sure we haven’t added extra keys that you weren’t expecting.
6. Now test your key, you should login directly yo target server.
[test1@server4 .ssh]$ ssh test1@server3 [test1@server3 ~]$
Note: if your server has not installed openssh-clients package another alternative will be:
$ cat id_rsa.pub | ssh user@server3 "cat >> ~/.ssh/authorized_keys"