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.

  • I cranked up the logging server-side, and it proved to be a problem with the permissions on the remote user's home directory. Problem solved! Thanks to all who gave answers.
    – Matt
    Jun 4, 2009 at 14:27

7 Answers 7


Yes, you can do this, just as you described it.

baruser@here ~$ ssh-add -l
4096 10:b3:fd:29:08:86:24:a6:da:0a:dd:c6:1e:b0:66:6a id_rsa (RSA)
baruser@here ~$ ssh foouser@remotesystem
motd message, etc.
foouser@remotesystem ~$
  • Thanks for the answer. I knew I wasn't crazy... :-) There must be something wrong with the remote system's SSH server configuration, preventing key authentication to work altogether.
    – Matt
    Jun 3, 2009 at 18:57
  • 4
    If you do "ssh -V foouser@remotesystem" you can get some information on what's going wrong. Oftentimes it's a permission error on ~/.ssh. Jun 3, 2009 at 19:01
  • 4
    not -V (shows version number) but -vvv (max verbosity)
    – Leven
    Mar 1, 2013 at 22:03

It's a bit of an aside, but.....

If you're always using the same username for a remote server, you may also find it useful to add a host into your ssh config:

Host remotesystem
    User baruser

That way you don't need to remember to specify user name when logging in, and you rule that out when having issues with keys in future.


Your local username doesn't really matter (aside from the private key having to reside inside your local user's home directory). Just copy the key to the remote user's authorized_keys section and it will work.


The permissions on the .ssh directories on both machines much be correct. Generally, that means 700 on the .ssh directory and at most 755 on the home directory. In addition to 600 on all the files in the .ssh directories.

If the user on the remote system is root, make sure that root can ssh. (PermitRootLogin in sshd_config) and that public key (PubkeyAuthentication) and if necessary RSA (RSAAuthentication) are enabled.

  • Isn't RSAAuthentication a completely separate method?
    – user1686
    Jun 3, 2009 at 19:11
  • RSA is one of the public-key algorithm supported by SSH (along with DSA.) It was the only method in SSH1. Jun 3, 2009 at 21:00

With any ssh related problems, the first thing to do is turn up the client verbosity:

ssh user@machine -vvv

If this fails to give you any insights as to what is wrong, you need to change the log level on the server and restart the daemon.

LogLevel DEBUG3

You should find the debug output in /var/log/auth.log (or where ever ssh is configured to log to). Once you've found the problem, remember to set it back to how you found it.


If you have SE Linux enabled, you will also need to do the following.

Add the SELinux label to authorized_keys so that it could be accessed by sshd.

semanage fcontext -a -t sshd_key_t ~foo/.ssh/authorized_keys
restorecon -Rv ~user/.ssh

Sounds like you're doing things correctly, but make sure that the permissions are correct on authorized_keys. They should be set to 600.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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