Published on

How to Setup SSH Public Key Authentication

SSH Image

Step1: Install SSH server

  1. Login to your server

  2. install ssh server

    sudo apt-get install openssh-server
    
  3. Make sure service is started

    systemctl status ssh
    

Step2: Generate public and private key

  1. Download ssh tools MobaXterm or Putty
  2. Generate key
    • MobaXterm: Tools > MobaXterm SSH Key Generator > Generate
    • PuTTygen: Generate
  3. Save private key file
  4. Copy public key in text box

Step3: Add public key to your server

  1. Edit key file

    nano ~/.ssh/authorized_keys
    
  2. Paste your public key

Step4: Config authentication method

  1. open file config
sudo nano /etc/ssh/sshd_config
  1. change some config
/etc/ssh/sshd_config
PubkeyAuthentication yes
PasswordAuthentication no
  1. restart ssh
sudo systemctl restart ssh

Step5: Test Authen with public key

  1. open mobaXterm
  2. Session > SSH
    • Remote host: host ip
    • Specific username: username
    • Advanced SSH settings: Use private key > Select private file
  3. OK

Reference