How to configure SSH public key authentication for password less login on Red Hat
How to configure SSH public key authentication for password less login on Red Hat |
Step 1: Generate SSH key pair using ssh-keygen command
# ssh-keygen
⦁ By default, ssh-keygen creates an RSA key pair of 2048 bits.
⦁ The default location is /home/<user>/.ssh/id_rsa (for the private key) and /home/<user>/.ssh/id_rsa.pub (for the public key)
Step 2: Copy public key generated into the authorized_keys file on the remote host
⦁ Method 1 - Copy public key to the remote machine
# scp $HOME/.ssh/id_rsa_key1.pub root@host.domain.com:/tmp
# cat /tmp/id_rsa_key1.pub >> /home/<user>/.ssh/authorized_keys (on remote host)
⦁ Method 2 - Instead of copy manually ssh-copy-id internally performs above commands
# ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-server
Step 3: Verify ownership and permissions of $HOME/.ssh and $HOME/.ssh/authorized_keys on the remote host
# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/authorized_keys
# chown -R <user>:<user> /home/your_username/.ssh
Step 4: Login to remote machine without password (private key machine to public key machine)
⦁ Default Login
# ssh root@remote_host.domain.com
Last login: Tue April 7 13:35:01 2019 from 10.67.1.77
[root@host ~]#
⦁ Login with specified key
# ssh root@host.domain.com -i /root/.ssh/id_rsa_key1
No comments: