0

I have a Raspberry pi 4 with a Linux OS & I am using a Macbook. The two machines are in the same LAN.

Raspberry pi IP address is 192.168.10.11. I can ping the Raspberry Pi from my MacBook terminal successfully.

On my MacBook, I generated a ssh key pair under ~/.ssh/, file names are raspberry and raspberry.pub.

In the terminal of my Macbook, I executed command:

ssh-copy-id -f -i raspberry.pub [email protected]

I verified that it successfully added the public key to the ~/.ssh/authorized_keys file of the Raspberry Pi. And I verified it by login as a root user in the Raspberry Pi.

Then, in a new terminal session of MacBook, I run ssh connection to the Raspberry pi:

ssh [email protected]

I thought it would not ask me password to login but I still get a password prompt asking for the root user password. And if I enter the correct password, I can login to Raspberry pie as a root user.

But why it asks password when making SSH login from my MacBook to the Raspberry Pi? I mean the public key is there under root user's ~/.ssh/authroized_keys of the Pi. Where do I miss?

4
  • 2
    At least with OpenSSH, non-default identity files need to be passed explicitly on the command line afaik ex. ssh -i ~/.ssh/raspberry [email protected] Feb 17, 2023 at 16:29
  • 3 things : Does the right of the keys 600 (if not the private key isn't read at all), then why don't use ssh -i to provide the real private key while login (it search perhaps for id_rsa) and lastly did you check if root can login remotely on Rasp-pi.
    – admstg
    Feb 17, 2023 at 16:31
  • Oh! yes, without specifying the private key, it would use the default id_rsa I suppose.
    – user842225
    Feb 17, 2023 at 16:32
  • Exactly that! I noticed alternatively I could just do ssh-add ~/.ssh/raspberry then the ssh connection could be established without specifying the private key ssh root@<IP of the PI>
    – user842225
    Feb 17, 2023 at 16:34

1 Answer 1

0

You can create a config file inside your .ssh folder and add IdentityFile /home/youruser/.ssh/mykey to set the default key to use.

After which, check that the SSH dir and its contents have the right permissions (you can run stat --format '%a' <file or dir>):

  • .ssh: 700
  • private key: 600
  • public key: 644
  • authorized_keys: 600
1
  • This also can be set per remote host, so individual remotes will use different keys, and yet you never need to specify them on the command line. Feb 18, 2023 at 5:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .