Simplify SSH Login

by Melvin Ram

Simplify SSH Login

Don’t you hate it when you want to ssh into a server and you have to type in something like this: ssh 123.456.789.01 -l myusername -p 2222

You can actually simplify this by editing your ~/.ssh/config file and adding something like this:

Host box1
Hostname 123.456.789.01
Port 2222
User myusername

Once you save and close this file, you can now ssh by doing this:

ssh box1

PS: This only applies to OSX & linux machines.

{ 6 comments… read them below or add one }

Lee Jones April 29, 2009 at 6:26 pm

Very helpful. I was doing something similar by adding an alias to my bash profile. Something like:

alias box1 = ‘ssh 123.456.789.01 -l myusername -p 2222′

Your tip seems much better, I’ll try it out.

Melvin Ram April 29, 2009 at 7:16 pm

The advantage with doing it in the ~/.ssh/config file is that other programs that use ssh can use it. For example, moonshine is able to reference it when setting up a server.

Steven Haddox May 29, 2009 at 3:36 am

My preferred method is to setup my boxes to utilize key-based authentication. Then I can disable password authentication and kill tons of pointless attempted logins (sparing my server some grief and securing it all at the same time). Since my username is the same on my local Mac's for development as it is for my remote servers I can simply login with:
$ ssh server.com
(if my login name was different it would merely be: $ ssh user@server.com)

melvinram May 29, 2009 at 3:53 am

Yep, that is my preferred way as well. I walk through how to do it in the first part of http://www.railsnotes.com/161-rails-server-setup/

This post was more for simplifying reaching the server… so that instead of doing ssh server.com -p 2222, you can just do ssh server. In any case, thanks for dropping in man. Hope to see you around more.

stevenhaddox May 29, 2009 at 3:56 am

Awesome, I hadn't quite made it back that far in the posts. Looks like a great blog (I'd already subscribed). Keep the great posts coming :)

melvinram May 29, 2009 at 4:18 am

I'm glad you like. It takes time to put together so it's nice to hear :)

Leave a Comment