Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to set my vps to use SSH keys for login instead of password. I've been reading tutorial after tutorial on how to set this up but I just can't set it up right.

So what I have done so far is the following

ssh-keygen -t rsa -b 4096

Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/
The key fingerprint is:
af:3a:f2:75:5f:c2:67:c8:ad:1d:0a:ab root@localhost

Copied Public Key into authorized_keys

cp root/.ssh/ /root/.ssh/authorized_keys

The issue is, how do I login via this key? Do I save the private key on notepad? Because if SSH key logs me in via ip, I don't think I can login because my ip is dynamic . Can someone help me?

share|improve this question
up vote 0 down vote accepted

The contents of have to be added to the file /root/.ssh/authorized_keys on the machine that you want to log into as root. On that ("target") machine, sshd also has to be configured to allow public key authentication. See sshd_config(5).

After this, you ssh as user root from some other machine to the target machine (by name or IP address, it doesn't matter). If you have protected the private key file /root/.ssh/id_rsa with a password then ssh asks you for the password so that it can read the private key.

share|improve this answer
jdthood let say I didn't provide an password for the private key and I go to my friend house and use putty to login my vps . Do I need to provide the private key? If so where? – Uncle Toby Jun 17 '13 at 10:33
You would need to provide the private key. You could consider carrying the id_rsa file with you on a USB stick; then you do ssh -i /path/path/path/id_rsa myhost. But in that case I would advise you at least to password-protect id_rsa. And even then, if you lose the USB stick then you should discontinue use of that keypair. – jdthood Jun 17 '13 at 14:17
ok thank you for your help jdthood – Uncle Toby Jun 17 '13 at 14:32

If you present an authorized key, the default configuration let you in regardless of where you come from.

share|improve this answer
ok , How do you present an authorized key? If i'm logging in putty via window . How do I present this private key? – Uncle Toby Jun 17 '13 at 10:14
You need to understand the concept of public/private keys thoroughly - I recommend reading up on the subject. But for putty, you need to generate a keypair on the the Windows machine in a form suitable for openssh, and ADD the public key to the authorized_keys file on the server. – Thorbjørn Ravn Andersen Jun 17 '13 at 11:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.