In this post will see how to enable SSH Authentication in RHEL7/ CentOS 7
SSH authentication will help us to log in a server/node without a password.
here we have two servers
server.lbcdomain.com : 192.168.43.226
node2.localdomain.com : 192.168.43.67
Now we need to install the OpenSSH packages using the command on both the servers.
[[email protected] ~]# yum -y install openssh
Now we need to start and enable the service permanently in this run level.
[[email protected] ~]# systemctl enable sshd.service [[email protected] ~]# systemctl start sshd.service
Then need to edit /etc/ssh/sshd_config file and change if Password authentication is set as No to yes
[[email protected] ~]# vi /etc/ssh/sshd-config
then change the below
Then save and exit from the file.
This is the right time to generate the key pair using command
Press Enter to confirm the default path (/home/root/.ssh/id_rsa)and the file name for RSA keys.
Next, for passphrase press enter to leave it blank.
After that, you will receive a message that mentioned RSA key pairs details.
[[email protected] ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/root/.ssh/id_rsa): Created directory '/home/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/root/.ssh/id_rsa. Your public key has been saved in /home/root/.ssh/id_rsa.pub. The key fingerprint is: d5:44:c4:ef:ef:49:ff:fe:e0:06:ed:d3:0e:71:e4:08 [email protected] The key's randomart image is: +--[ RSA 2048]----+ | ++ | | o. | | . E. .| | . ..+ | | S oo o| | . oo | | oo+ | | .=o=| | ..*X| +-----------------+
[[email protected] root]$ cd ~/.ssh/ [[email protected] .ssh]$ ls id_rsa id_rsa.pub
We generated keys above and we should copy the public key to the remote server which we need to allow to access this server without password
use the command to copy the public key
#ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Now open /etc/ssh/sshd_config file in node2 server and make the below changes.
save and exit from the file.
Now restart the sshd service on both the servers
RHEL7: systemctl restart sshd RHEL6: service sshd restart
We almost completed the ssh authentication. To test this connection will try to log in from server.lbcdomain.com to node2.lbcdomain.com server using ssh
#ssh [email protected]