Is production: true
#migrated

Title: Use public/private key for authentication

Created: 19 Mar 2023 Modified: 19 Mar 2023

Description:



[Legacy Link]

[Link]

Instructions

  1. 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
    
  2. 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
    
  3. Test the connection

    ssh -i ~/.ssh/id_rsa {user1}@{host1}
    
  4. Disable password authentication

    sudo vim /etc/ssh/sshd_config
    #########################
    #change from yes to no
    PasswordAuthentication no
    #########################
    sudo systemctl restart sshd.service