VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-20-04?comment=88495

โ‡ฑ How to Set Up SSH Keys on Ubuntu | DigitalOcean


How to Set Up SSH Keys on Ubuntu

Updated on March 11, 2026

By Anish Singh Walia

Sr Technical Content Strategist and Team Lead

English
Not using Ubuntu 20.04?
Choose a different version or distribution.
Ubuntu 20.04
๐Ÿ‘ How to Set Up SSH Keys on Ubuntu

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author

๐Ÿ‘ Anish Singh Walia
Anish Singh Walia
Author
Sr Technical Content Strategist and Team Lead
See author profile

I help Businesses scale with AI x SEO x (authentic) Content that revives traffic and keeps leads flowing | 3,000,000+ Average monthly readers on Medium | Sr Technical Writer(Team Lead) @ DigitalOcean | Ex-Cloud Consultant @ AMEX | Ex-Site Reliability Engineer(DevOps)@Nutanix

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

im trying to migrate from another host to DO and this is keeping me for days from migrating my websites from the other host. iโ€™ve been trying literally everything and still no success to connect to root in fact yesterday i created a sudo user (as shown in this tutorial) but i couldnโ€™t edit files when connected via ftp client with that user. then i tried to connect to root again, and guess what: โ€œthe almighty PERMISSION DENIEDโ€. iโ€™ve been deleting around 20 droplets and created new keys on my computer, then copied the keys to the authorized_keys file, and when i try to login to root the PERMISSION DENIED is haunting me even in my dreams, man! i knew DO is a bit complicated but i never thought i would stuck at this point which had to be so straight forward. is there anything you could help me with this in a step by step basis because i cant even articulate a question because i tried a lot of things and none seems to work. thanks!

Great article however how do I remove the password from the created user? So, I can only SSH into it like root.

FYI: On Ubuntu 20.04 and if you are using SSH Keys, after you create your keys and provision the DO server, the username for login is root.

For example:

me@my-workstaton:~$ ssh root@138.197.173.34

Once on the DO server, I can create a regular account and I can add the contents of my id_rsa.pub file to the new account.

I then should be able to login my new account on the DO server.

I then add that user account to the sudoerโ€™s file.

I had some trouble with copying the intended public key when specifying a different path other than id_rsa (for example, I named it blah_key, and it lived at ~/.ssh/blah_key). Every time I attempted to copy via ssh-copy-id utility, it would grab the key under the default path. The following command helped me set the intended key as an authorized key on the server:

ssh-copy-id -i ~/.ssh/mykey user@host

TLDR; if a user chose to write their key to a different path other than the default (id_rsa), hereโ€™s how you copy that public key from that path.

Thank you for this tutorial to setup key based authentication. I have one comment, if we disable the Password Authentication for SSH, it will not allow to establish a ssh session on the server as it doesnโ€™t have public keys in the authorized keys for its own users. I solved this by creating keys using ssh-keygen and copying the public key to authorized keys list.

Nice article. Is there a PDF, Sphinx or Word version for offline use ?

donโ€™t disable password authentication before you make sure ssh auth is working correctly. I got caught and cant log back in.

I am getting permission denied when trying to upload the key.

๐Ÿ‘ Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOceanโ€™s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow โ€” whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

ยฉ 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.