Description:
Generate key file
#Generate rsa key pair
ssh-keygen -t rsa
#Or generate rsa with specific bit "-t" option
ssh-keygen -b 8192 -t rsa
Copy public file to the server aimed to connect through ssh
scp -P{port} ~/.ssh/id_rsa.pub {user1}@{host1}:~
#ssh to host1
ssh -P{port} {user1}@{host1}
#make directory if not exists
mkdir ~/.ssh
#make file is not exists
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
#exit ssh session
Test the connection
ssh -i ~/.ssh/id_rsa {user1}@{host1}
Disable password authentication
sudo vim /etc/ssh/sshd_config
#########################
#change from yes to no
PasswordAuthentication no
#########################
sudo systemctl restart sshd.service