Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 made a key, but it logs me back out as i try to setup passphraseless logins to localhost:

$ rsa-keygen -t rsa
$ cat id_rsa.pub > authorized_keys
$ ssh localhost

The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is bb:a6:5e:46:c9:b5:e9:46:bd:43:c1:6e:cd:3b:e5:ea.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
Connection closed by ::1

The same thing happens when I try to login with using the hostname as well. What am I missing?

share|improve this question
Does it work if you don't use your public key? (You can try with ssh -o PubkeyAuthentication=no localhost) – Michael Mrozek Nov 15 '10 at 5:28
could you run tail -F /var/log/secure.log in one terminal, while attempting to ssh localhost in another terminal, so we can see what error messages if any are occurring? – N J Nov 15 '10 at 7:59
Post the output of ssh -vvv. (This is something you should always do when asking about ssh failing to connect. Anonymize user and host names if necessary.) If you have a ~/.ssh/config, try without or post its contents. – Gilles Nov 15 '10 at 19:19
3) OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009 – shigeta Nov 17 '10 at 6:04
1) ssh -o PubkeyAuthentication=no localhost demands a password then says permission denied... hey wait ssh localhost also fails - what does that mean? – shigeta Nov 17 '10 at 6:06
up vote 0 down vote accepted

If you provide your SSH key by hand does it work?

ssh localhost -i id_rsa

If so, the problem is most likely your SSH agent that didn't register your new key

share|improve this answer
well its true this doesn't work. how do i register the new key then? – shigeta Nov 17 '10 at 6:02
I think this might be the right answer... Under system preferences -> Sharing -> remote login I had to add the user to allow ssh for that account. Then all the above worked fine... – shigeta Nov 17 '10 at 6:23

You could try to use the following command juts after calling the ssh-keygen command:

ssh-copy-id -i id_rsa.pub localhost

It should copy your public key to the remote host (here your own computer as you used localhost) and activate it in the proper file.

Note: Sometimes and with older version of sshd (the SSH serveur process) the file is named authorised_key, check you sshd man page for the exact name.

share|improve this answer
ssh-copy-id is not found. – shigeta Nov 17 '10 at 6:02
thanks for the hint though. i did check and it likes the 'authorized_key' file, but it still asks me for a password :P any other ideas? – shigeta Nov 17 '10 at 6:03
On your SSH server, did you check if it's configured to accept key authentication? Look in the file /etc/ssh/sshd_config (or what it appropriate on Mac OS X), and verify the option PubkeyAuthentication, it should be 'yes'. Try to activate logging facilities (on Unices, it's SyslogFacility and LogLevel that you have to set), and the log are usually in /var/log/messages. However, I'm not sure how this work on Mac OS. Perhaps, check the man page of sshd_config or sshd. – Huygens Nov 17 '10 at 18:56

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.