1

I have two linux users

  • user1 - regular account with auth key stored in /home/user1/.ssh/
  • user2 - service account without home directory

How can user2 access user1's keys to connect to the remote server? Is there any way we can access keys using a shared folder between two users?

1
  • All users have a home directory. It may not exist though. Possibly change the home directory, then create it. This is a X-Y problem. Dont share keys. Create new ones for each user.
    – user10489
    Sep 4, 2023 at 11:16

2 Answers 2

1

service account without home directory

Really? That's very unusual. There is no home directory in /etc/passwd or the entry points to a non-existent path?

While it is possible for the service account to use ssh keys without a home directory (ssh -i /path/to/key user@host) your life will be a lot simpler of you just add a home directory.

Then there's lots of ways, but I think I would go with a ~/.ssh/config for each user pointing to the shared directory:

host *
   user sshusername
   IdentityFile /path/to/id_ecdsa
0

This looks like a bad idea:

Each user having their own keys, and the corresponding public key being put on the destination user@destination:.ssh/authorised_keys file (with proper comment to remember whose public key it is) is recommended instead : that way if "user2" leaves the company the public keys can be removed (by removing the public key entries and deleting the private key) without impeding "user1"

However, if after careful consideration and inquiry about the security-minded persons in your company it is still thought as the way to go, you could simply have an administrator account create hard-links of the key of user1 inside user2/.ssh/ ... But I strongly advise against doing this.

Or if "user2" has read access to ~user1/.ssh directory and its content (use proper groups for that?): just do :

ssh -i ~user1/.ssh/thekey  remoteuser@remotedestination

You must log in to answer this question.

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