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.
[root@server ~]# yum -y install openssh
Now we need to start and enable the service permanently in this run level.
[root@server ~]# systemctl enable sshd.service [root@server ~]# systemctl start sshd.service
Then need to edit /etc/ssh/sshd_config file and change if Password authentication is set as No to yes
[root@server ~]# 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.
[root@server ~]# 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 sshuser1@server The key's randomart image is: +--[ RSA 2048]----+ | ++ | | o. | | . E. .| | . ..+ | | S oo o| | . oo | | oo+ | | .=o=| | ..*X| +-----------------+
[sshuser1@server root]$ cd ~/.ssh/ [sshuser1@server .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@example.com
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