0

I have multiple Raspberries, each with a unique key eg: pi1_id_rsa, pi2_id_rsa and pi3_id_rsa. I want to do ssh pi1 or ssh pi2 to shell into a pi.

For this, I have put in ~/.ssh/config,

...

Host pi1
    Hostname [email protected]
    User name1 # This is hostname, maybe it's wrong?
    IdentityFile ~/.ssh/pi1_id_rsa

... 

sudo ssh [email protected] works, however it does not use ssh key, instead it asks for a password and the point of keys is to avoid passwords.

Doing ssh pi1, gives the error ssh: Could not resolve hostname [email protected]: Temporary failure in name resolution. The same address is resolved with password login. The difference here is that ssh should use Hostname in .ssh/config to connect to the pi.

Perhaps, the problem is that everything is on a local network and .ssh/config is not meant to resolve addresses in this way?

Edit: It may not be completely clear, the idea of this is have a good amount of security, the ssh setup should be scalable AND elegant. I looked at a few guides for setting up ssh keys on raspberry and none of them were scalable and/or secure (eg: many guides suggest reusing keys made for git or another pi).

Thanks.

9
  • "I have put in ~/.ssh/config" It is far from clear what you are trying to do. Have you created private/public keys? In general you put both in ~/.ssh on the host and add public key to client
    – Milliways
    Sep 9, 2023 at 11:14
  • @Milliways Apologies. Yes. In IdentityFile you can see path and name of private key. The last line of first paragraph is the aim: "I want to do ssh pi1 or ssh pi2 to shell into a pi.". Thanks.
    – rkochar
    Sep 9, 2023 at 11:26
  • Again what you want to do is unclear. I have 9 Pi and can ssh into any Pi (I currently have open ssh sessions to 4) - they all have the same public key.
    – Milliways
    Sep 9, 2023 at 11:30
  • @Milliways I think you are asking "What is the point of this". I have added an edit to the original post at the bottom critiqing existing approaches. For your pleasure (or inspiration), my git and gpg keys are setup like this because I have multiple git accounts on various providers (GitHub, GitLab, Azure DevOps, etc) and require security and convenience in using all of them.
    – rkochar
    Sep 9, 2023 at 11:40
  • If there are still some doubts, I want to do ssh pi1 and shell into pi1. ssh pi2 should shell into pi2. This must be done securely and the approach must be scalable. I have already done most of the work: ssh finds the correct key to use for the correct pi, but can not connect to the pi.
    – rkochar
    Sep 9, 2023 at 11:43

2 Answers 2

3

The problem is with Hostname [email protected] the [email protected] is not a valid hostname. Remove the pi1@ part: Hostname name1.local.

It looks like the user name is pi1 based on your ssh example. So, you probably also want User pi1 in your .ssh/config.

Host pi1 name1 name1.local
    HostName name1.local
    User pi1
    IdentityFile ~/.ssh/pi1_id_rsa

Then you should be able to do ssh pi1 or ssh name1 or ssh name1.local, they're all equivalent.

1

Your real question (based on Comments) seems to be how to specify a private key.

Your host can have multiple private keys (although why you would want to do this on a private network eludes me).

ssh -i identity_file

Selects a file from which the identity (private key) for public key authentication is read. … 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 configuration files).

1
  • 1
    This would work but we can do better by automating selecting private key and Hostname with the config file. In addition, the config file also gives us other advantages such as specifying rules.
    – rkochar
    Sep 10, 2023 at 6:44

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