Instructions
-
Generate key file
1 2 3 4 5#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
1 2 3 4 5 6 7 8 9 10 11 12 13 14scp -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
1ssh -i ~/.ssh/id_rsa {user1}@{host1} -
Disable password authentication
1 2 3 4 5 6sudo vim /etc/ssh/sshd_config ######################### #change from yes to no PasswordAuthentication no ######################### sudo systemctl restart sshd.service