Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to secure my VPS, so I'm trying to use RSA authentication, obviously I don't want to be logging in as root, so I disabled PermitRootLogin but I also disabled PasswordAuthentication

My question is, how can I get my RSA key to authenticate with a regular user. Like I said, I got it to work with root while I had those settings enabled, but I have no idea how to make it work without them on, with a regular user.

PS. I'm on Ubuntu 10.04

Thanks, Archey

share|improve this question
    
Did you deactivate PasswordAuthentication before you had a pubkey on the server? –  Baarn Jan 8 '13 at 18:36
    
No, I deactivated after I got the RSA key working with root, I thought it would just work with any other use too. –  Archey Jan 8 '13 at 19:05
    
Well, you need a key in the authorized keys file for every user afaik. I think you have locked yourself from your server and need to contact support (although I might be wrong). –  Baarn Jan 8 '13 at 19:09
    
I'm not worried about locking myself out. How does the authorized_keys file determine which public key is for which user? –  Archey Jan 8 '13 at 19:12
    
the user is determined by how you log in eg ssh user@host, the server then checks the users .ssh folder on the server for the authorized_keys file. I am guessing, but afterwards it maybe checks the /etc/ssh/.ssh/authorized_keys file (path might differ) for a fitting key. If you stored your root-pubkey in that file you should still be able to log in with another user, if you use the same private key. –  Baarn Jan 8 '13 at 19:16
add comment

2 Answers

You should be able to put the public key in ~/.ssh/authorized_keys or ~/.ssh/authorized_keys2 (mode 644) and have it work just like it does with the root account.

share|improve this answer
add comment

You'll want to do a bit of set-up first on the server.

1) Generate your key (looks like you are good there)

ssh-keygen -t rsa -b 1024 -C "Comment if you want it" -f id_arbitraty_name

2) Cat the Public (*.pub) key to the authorized_keys folder for the users you want to login as (As @John mentioned, 644 for these).

cat id_arbitrary_name.pub >> /home/<username>/.ssh/authorized_keys{,2}

(The expansion will do it to both authorized_keys and authorized_keys2)

3) Download the private key

scp user@server:/loc/on/server/id_arbitrary_name ~/.ssh/

4) Set safe permissions for the private key 600, since it's on your local machine

chmod 600 ~/.ssh/id_arbitrary_name

Optional:

5) If you want to save typing locally, set-up a local config file in ~/.ssh/

vim ~/.ssh/config

Host SomeIdentifyingName
    Hostname domain.com
    User username
    IdentityFile ~/.ssh/id_arbitrary_name

That allows you to just type ssh SomeIdentifyingName (tab completion works on that!) and connect.

Note Looks like you disabled root login, so this doesn't really apply to you. However, for future readers:

All the above being said, segregation of Keys is suggested. Otherwise, if I don't specify a username and the server prompts - root is an obvious one to try!

share|improve this answer
add comment

Your Answer

 
discard

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.