Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Digital Ocean - Add SSH key to droplet after creation

David Carr

Digital Ocean VPS Tutorials

    When creating a droplet you can add an SSH key during setup, later if your key changes you won’t be able to SSH into the server.

    The advice is to login to the droplet and add the SSH key to:

    ~/.ssh/authorized_keys

    I found trying to copy and paste the key difficult.

    Another approach is to turn on password authentication by editing sshd_config.

    vi /etc/ssh/sshd_config

    Change PasswordAuthentication from "no" to "yes".

    Restart the server.

    service sshd restart

    Exit the server.

    From your computer, copy the ssh key.

    cat ~/.ssh/id_rsa.pub

    Now ssh in from your computer.

    ssh root@ip

    Enter the password

    Paste the ssh key.

    ~/.ssh/authorized_keys

    You will now be able to login without using the password, at this point you can turn PasswordAuthentication from yes to no to disable password authentication inside

    vi /etc/ssh/sshd_config

    Restart the server.

    service sshd restart

    To add a SSH key to a user, add a .ssh folder.

    mkdir -p /home/username/.ssh

    Make authorized_keys file and add the id_rsa.pub.

    touch /home/username/.ssh/authorized_keys


     

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.