1

Here is my situation.

I use Putty to make an SSH connection from Windows 10 to my Raspberry Pi2 (running latest Raspbian).

If I use just my standard Password to login, everything works fine.

If I use a Public/Private key-pair (with the Putty key generator and Pageant) I have a problem.

I store the public key (as one line) on raspberry in;

~/.ssh/authorized_keys

However I cannot login via Putty, I get a failed authentication.

If however, I move the authorized_keys file (where the public key is stored) to: /etc/ssh/Username/authorized_keys and I edit my sshd_config file to retrieve the key from there - everything works fine!

So, as I see it, I have some sort of permission problem in the folder ~/.ssh, which causes the authorized_keys file to be unavailable.

I have 2 questions;

  1. Is it safe if I leave my public key authorized_keys in the /etc/ssh/Username/ folder?

  2. If it is not safe, what should I do?

Edit;

Here is what I get when I use ls -la on my folder ~/.ssh ;

total 12
drwx------  2 MyPi MyPi 4096 Dec 21 16:40 .
drwxr-xr-x 29 MyPi MyPi 4096 Dec 21 17:25 ..
-rw-------  1 MyPi MyPi  398 Dec 21 16:54 authorized_keys
1

Since it is a public key you are copying to the Pi you can leave it in /etc/ssh/username folder. The public key can be shared freely and does not present a security issue - this is not true for the private key which should never be shared with anyone. However, it would be better to figure out what is wrong with your current configuration.

You mention possible permissions issues, but you do not mention what the permissions are on the /home/pi/.ssh (assuming you are trying to login as pi) and the /home/pi/.ssh/authorized_keys files. They should be 700 (i.e. drwx------) and 600 (i.e. -rw-------) respectively. You can verify this with the ls -la command. If the permission is wrong you can change it with chmod 700 /home/pi/.ssh.

In addition they should both have the owner and group set to pi (again assuming that is the user your are trying to login as). You can verify this with the ls -la command as well ls -la /home/pi/ and ls -la /home/pi/.ssh/ respectively.

I wrote a post on setting up passwordless logins from Windows for our blog.

  • 1
    Additionally it might be worth mentioning that the private id files which the man page for ssh mentions could be: ~/.ssh/identity, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519, and/or ~/.ssh/id_rsa MUST have no permissions for group or other persons otherwise ssh will simply ignore them. – SlySven Dec 21 '16 at 18:18
  • @SlySven good point, but those are not on the Pi – Steve Robillard Dec 21 '16 at 18:21
  • Here is what I get when I use ` ls -la` on my folder ` ~/.ssh ` ; total 12 drwx------ 2 MyUserPiName MyUserPiName 4096 Dec 21 16:40 . drwxr-xr-x 29 MyUserPiName MyUserPiName 4096 Dec 21 17:25 .. -rw------- 1 MyUserPiName MyUserPiName 398 Dec 21 16:54 authorized_keys – Ivan_Grozny Dec 21 '16 at 22:06
  • 1
    @Ivan_Grozny DO NOT post detail into Comments. Edit into your question. – Milliways Dec 22 '16 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.