Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have a keyfile named KEY, which has KEY and I upload the pub to authorized_keys, and add the private with

ssh-add /home/user/.ssh/KEY

But when I try to connect with ssh, it keeps asking me for the password.

If I generate a key with ssh-keygen and leave the default key name, uploading the pub and loading the private, it does not request a password.

What could the problem be?

share|improve this question
up vote 6 down vote accepted

With ssh -vvv you can get the debug output and it will probably tell you that it can't authenticate with ~/.ssh/id_rsa (ssh's default key file). The answer is to tell ssh which key to use:

ssh -i /home/user/.ssh/KEY

You can also add your per-host keyfile to your .ssh/config, then you'll just have to type ssh and user/key are selected automatically.

Example entry for .ssh/config (For more information see man ssh_config):

Host mysshserver
User myusername
IdentityFile ~/.ssh/mykeyfile

Explanation of keyfiles from man ssh:

 -i identity_file
             Selects a file from which the identity (private key) for RSA or
             DSA authentication is read.  The default is ~/.ssh/identity for
             protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro‐
             tocol version 2.  Identity files may also be specified on a per-
             host basis in the configuration file.  It is possible to have
             multiple -i options (and multiple identities specified in config‐
             uration files).
share|improve this answer
I'm getting a bad configuration option when adding the ssh -i line: /home/gabriel/.ssh/config: line 2: Bad configuration option: ssh – Gabriel A. Zorrilla Sep 12 '10 at 20:48
@Gabriel: "ssh -i /home/user/.ssh/KEY" works only from the commandline. The configfile option is different and I've updated my answer with an example entry for the .ssh/config file. – agporwfnz29 Sep 12 '10 at 21:01

To set up your key files correctly (How-To here), note the following:

In case your host .ssh directory and files don't have the right permissions AND / OR your remote user home directory doesn't have the right permissions, ssh will keep asking for password although it finds the key file.

You can see if your key file / files are being offered using ssh -vvv user@host

Example output:

debug1: Offering DSA public key: /Users/<user>/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

Check both remote user home directory and remote .ssh directory permissions

For example, the permissions should be:

$ls -ld .ssh
drwx------ 2 <owner> <group> 4096 2011-12-29 20:39 .ssh

$ls -ld ~/
drwxr-xr-x 28 <owner> <group> 4096 2011-12-29 20:15 /home/<user>/ 
share|improve this answer

The article How to set up keyfile-based SSH Logins explains the problem and the solution

when you're on system A and type "ssh username@B", system B will check to see if the key corresponding to your system A "id_dsa" file is among those known to your user (i.e., it is in the authorized_keys file in your user's .ssh subdirectory). If it is, it won't ask for a system password, it will ask for the key's associated passphrase, which means that if you've set it up with no passphrase, you're on without having to type anything.

See the article for detailed instructions.

share|improve this answer

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.