Can I use SSH key authentication to log into a remote system with a different username?

Suppose I have a remote system named “remotesystem”, and a user account “foouser” on that system.

I know that on my local system, I can generate an SSH key pair as local user “foouser”, put the public key in the “/home/foouser/.ssh/authorized_keys” file on “remotesystem”. When I SSH as “foouser” from my local system to “remotesystem”, SSH uses the key pair to authenticate me.

But what if my local username is not the same as the username on the remote system? That is, what if I want to SSH as local user “baruser” to “remotesystem”? Obviously, I will need to generate a key pair for “baruser” and add the public key to “/home/foouser/.ssh/authorized_keys”. Then, I should be able to “ssh foouser@remotesystem” while logged in as “baruser” locally, and SSH will use the key pair to authenticate, right?

I’m asking because I am trying to get the key authentication working in this scenario, without success. I’m not sure if its due to the username mismatch, or a configuration issue with the SSH server on the remote system.


Leave a Reply