Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to use another computer to access my ssh server. This is because a recently implemented vpn at my university doesn't work on my current computer and I have lost access to the server.

I ssh via encrypted ssh keys. Can I copy these keys to the new computer (on which the vpn works). I tried copying the id_rsa and id_rsa.pub files in the ~/.ssh folder but it doesn't recognize the keys and there is no prompt to input a password to decrypt the keys.

EDIT: I can't access the server to generate a new key pair for the new computer and am out of the country so can't physically access it.

Thanks.

share|improve this question
    
Is "id_rsh" a typo? –  ændrük May 10 '12 at 13:28
    
thanks. typo fixed. –  benj May 10 '12 at 13:35
1  
You might learn more about the problem by trying ssh -v -i ~/.ssh/id_rsa ssh-server. –  ændrük May 10 '12 at 13:57
    
tried that. It seems to send the keys but never asks for a password to unencrypt them. I also get a strange generic message "Roaming not allowed by server". Guess private keys are just not meant to be copied ;). Looks like I'm just going to have to trust someone with physical access to manually log into my server and change the ssh settings. Thanks for your help. –  benj May 11 '12 at 8:41

3 Answers 3

up vote 8 down vote accepted

Check the permissions and ownership of your private key file. From the manual,

These files contain sensitive data and should be readable by the user but not accessible by others (read/write/execute). ssh will simply ignore a private key file if it is accessible by others.

Typically the key files should look like this,

$ ls -l ~/.ssh/id_rsa*
-rw------- 1 benj benj 1766 Jun 22  2011 .ssh/id_rsa
-rw-r--r-- 1 benj benj  388 Jun 22  2011 .ssh/id_rsa.pub

which you can enforce via:

$ chown benj:benj ~/.ssh/id_rsa*
$ chmod 600 ~/.ssh/id_rsa
$ chmod 644 ~/.ssh/id_rsa.pub
share|improve this answer
2  
thanks. That's useful to know. When you copy a file to another computer the permissions do seem to change to that user. I ran the chmod and chown scripts in case. Unfortunately it didn't help my issue. –  benj May 11 '12 at 8:35
    
@benj It works fine for me. Why don't you accept the answer? –  Ionică Bizău Dec 13 '13 at 8:09
    
@Johnツ this might have been part of the problem for me but there appeared to be other issues. I eventually got someone to physically login to the server and set up a new key. But will accept this as it probably covers a key issue. –  benj Dec 13 '13 at 15:27

Try running ssh-add before you SSH into the server - you should then be prompted for the password and then subsequent ssh connects can use your private key.

The ssh-add command adds the keys to the key agent.

share|improve this answer
    
I don't think this is the issue, as 1) the SSH client can cope without a functional key agent, 2) the server wouldn't respond with the "roaming not allowed" message and 3) the ssh client would have it's own error message when talking to the key agent fails in some way. I've made my thoughts about it an answer. –  gertvdijk Jan 16 '13 at 12:44
    
This fixed the problem for me. Also see Github documentation for this. –  Ionică Bizău Aug 21 '13 at 5:03

Encrypted private keys hold their corresponding public key unencrypted. This is how the SSH client can connect to the remote server without asking you the password (it only offers the public part at that point). Whenever the server accepts the public key, the client on your PC wants to decrypt the private key and will ask you for the passphrase.

Now, whenever the server only accepts connection from a specific IP address, this is declined already in the first step and explains the message you got from the server "Roaming not allowed by server".

So, my best guess is that your server is restricted in some way to allow only specific IP addresses for this key. You can do this in several ways, but this is a common one in ~/.ssh/authorized_keys:

from="192.168.1.2" ssh-rsa AAAAB3NzaC[...]

To prove that you can read the public key out of an encrypted private key without password, run:

ssh-keygen -y -f /path/to/private/key
share|improve this answer

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.