How to attach a public key to a specific user, so that I don't have to type the user name every time?

I've put the user's public key in the authorized_keys file, but when the user logs in, he has to ssh user_name@server to login.  Is there a way to juse type ssh server instead?  Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The ssh command will default to:

    1) Logging in to the remote server as the same username as the currently logged in local user.
    2) Using the ~/.ssh/config config file

So if you're logged into Server A as the user "johndoe", then when you execute


It will attempt to login as "johndoe" on Server B, by default.

If you want to override this behavior, you specify the username e.g.


You can also create a per-user default ssh config file,  ~/.ssh/config to override the default flags that SSH uses.

Read the MAN page here:

Note that the ~/.ssh/config file has special requirements for the permissions. You MUST set the permissions so that the user has access, and everybody else does NOT have access, so when you create the file, you should run chmod on it, e.g.:

     touch ~/.ssh/config
     chmod u=rw,g-rwx,o-rwx ~/.ssh/config

You could put the following directives inside the ~/.ssh/config file:

User janedoe

Open in new window

And then, by default, the ssh command will attempt to login to remote servers as the user "janedoe", instead of the currently logged in local user, "johndoe".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thomaszhwangAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.