Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have this in my ~/.ssh/config directory:

Host 12.34.56.78
    IdentityFile ~/.ssh/my_identity_file

When I ssh to 12.34.56.78, everything works fine. I'm asked for the passphrase for "my_identity_file" and I can connect to the server.

However, sometimes I'd also like to ssh to another server. But whatever the server, if I do:

ssh account@anotherserver.com

I'm also asked for the passphrase for "my_identity_file" (even though the server has a different ip address). This is very annoying because I don't have the public key for this file set up on all my servers. I'd like to connect to this other server (an old shared hosting account) with a password, and now I cant.

How do I manage to use the key authentication only with one server, and keep using password by default for servers that aren't listed in my ~/.ssh/config ?

Thanks for your help.

share|improve this question
    
Is my_identity_file the actual name of the file or is it identity, id_dsa or id_rsa? Those are the default names that ssh looks for. –  Etan Reisner Jul 1 '13 at 16:51
    
"my_identity_file" is the actual filename. I'm not using any of the default key names. I'm surprised that the ssh client wants to use that key while I thought I made it clear in the config file that I only wanted to use this key when connecting to the ip 12.34.56.78. –  John Smith Optional Jul 1 '13 at 22:19
    
That's interesting. As an aside though if you just hit enter on the passphrase prompt ssh will skip the key and drop back to prompting for password auth. –  Etan Reisner Jul 2 '13 at 1:49
    
What do you see if you run ssh -v account@anotherserver.com? Near the top ssh should spit out some information about what config sections (if any) it is applying. That might tell you something. (You can go up to -vvv for even more debugging information if you want to see if anything else useful shows up.) –  Etan Reisner Jul 2 '13 at 1:50
    
When I type enter at the passphrase prompt, nothing happens (the ssh client quits and I'm back to the shell prompt). The same happens with the -v option. –  John Smith Optional Jul 2 '13 at 10:58
show 4 more comments

migrated from serverfault.com Jul 2 '13 at 19:06

This question came from our site for professional system and network administrators.

2 Answers

You will probably find useful using a tool such as "ssh-add" that will keep your deciphered private key in memory, so it won't ask for your passphrase when you need it.

So, when you will want to ssh another host,

1/ If your public key is on it, ssh will authentificate you automatically

2/ If your public key isn't on it, ssh will try to authenticate you with the key, will fail, then ask you for the password.

But as said by Etan Reisner, it looks like you called your identity file by the default name, otherwise ssh wouldn't be trying using it. If you don't want to use an ssh agent, just change the name of your private key

share|improve this answer
    
Thanks. Actually, I'm already using ssh-add, so I'm only asked for this passphrase once. But why does the ssh client want to use this key while I only mentionned it in the 12.34.56.78 section of my config file? –  John Smith Optional Jul 1 '13 at 22:22
add comment

The Host in the config file is actually the short name you want to identify the server as. You need to use hostname to identify by hostname or IP. Also you can limit to a given user as well

Try something like

Host myhost
Hostname a.b.c.d
User myuser
Identityfile my-identity-file

This should use that key file only for the specified hostname It will also use that user if you do not specify one

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.