krlaboratories

how generate ssh keys and copy to server

Dec 22nd, 2021 (edited)
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.48 KB | None | 0 0
  1. ssh-keygen -t rsa
  2. save generated keys to /home/user/.ssh/ directory
  3. will be 2 keys - id_rsa (private) and id_rsa.pub (public)
  4.  
  5. copy pub key to the VPS:
  6. ssh-copy-id -i /home/user/.ssh/id_rsa.pub root@XXXXXXXXX
  7.  
  8. after successfull copy need change SSH config on server:
  9.  
  10. nano etc/ssh/sshd_config
  11. and change 'PasswordAuthentication yes' to 'PasswordAuthentication no'
  12. CTRL+O
  13.  
  14. sudo systemctl restart sshd.service
  15.  
  16. ssh -p 22 -i /key username@XX.XX.XXXX
  17.  
  18. login to ssh with keypair.
Advertisement
Add Comment
Please, Sign In to add comment