ssh config file

Posted on Sunday, August 10, 2014


With the new job came a new computer, an official company computer all set up for me.   They did a good job setting it up and I do have admin rights to it, but they also set up my default username on it.  And of course the username is not my go to default username.

As a result every time I need to ssh into one of my boxes from my new laptop I need to prepend my username.  For example


> ssh username@www.whiteboarcoder.com


If my machine had the same username I would not have to add this at all.


If you do not know your current username just run the following


> whoami


I poked around trying to see if there was a way it could default to a different user when I ssh'd to a certain box and I found this page

Long story short you can add some Hosts to a configure file in your .ssh directory.

Open the config file for editing


> vi ~/.ssh/config


And place something like the following in it (Adjust it for your needs)



####################
#
# Personal
#
###################
Host white
   Hostname www.whiteboardcoder.com
   user username



Now if I run this from the command line


> ssh white


Its as if I am runnig


> ssh username@www.whiteboardcoder.com


You can do add as many as you want for example


####################
#
# Personal
#
###################
Host white
   Hostname www.whiteboardcoder.com
   user username

####################
#
# Work
#
###################
Host yahoo
   Hostname www22.yahoo.com
   user pbailey




You can also designate ports to use as well (if you use non-standard ports)


####################
#
# Personal
#
###################
Host white
   Hostname www.whiteboardcoder.com
   user patman
   Port 2222



This is a big time saver (especially if you have dozens of different servers you access, you can make short quick names for them for example web1, web2, web3, web4….)


References
[1]        Simplify Your Life With an SSH Config File
                        http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/ 
                Accessed 08/2014