Skip to content

How To Setup Key Based Ssh Authentication

How to Setup key-based (SSH) authentication on your Server#

  1. Create the key pair on client

    ssh-keygen -t rsa

    Convention over configuration keep the default location

  2. Install the public key on remote server

    ssh-copy-id -i $HOME/.ssh/

    Not if you don’t have the private key you need to use the -f option:

    ssh-copy-id -f -i $HOME/.ssh/


    scp $HOME/.ssh/
    No ssh-copy-id installed?#
    First create .ssh directory on server
    ssh umask 077; test -d .ssh || mkdir .ssh
    cat local file and pipe over ssh to append the public key in remote server
    cat $HOME/.ssh/ | ssh cat >> .ssh/authorized_keys
  3. Test

    ssh -T
    scp foo.txt

    Get rid of password:

    eval $(ssh-agent)

    add passphrase for private key maintained by ssh agent


    Try login you shouldn’t be prompted for password


Now to Disable Password Authentication on your server#

sudo vim /etc/ssh/sshd_config
PasswordAuthentication no

Restart SSH

sudo service ssh restart