Archive for October, 2010

Missing PuTTY on your Mac? Use the alias command

Wednesday, October 13th, 2010

If you have moved to Mac OS X from Windows you may be like me and miss the convenience of the saved server settings in PuTTY. These settings allowed you to telnet/ssh into your servers without having to remember the IP of each one. There are numerous ways around this of course, but here is a tip that may come in handy…

Use Alias Shortcuts

The 'alias' command allows you to create an alias, or shortcut, to a longer command. For example you could create a shortcut to open TextEdit from the command line like so:

  • Open the Terminal app
  • Type  the following: 

    alias te='open /Applications/'

  • Press Enter
  • Now type "te". TextEdit should open

So how can we use the alias command to replace the convenience of PuTTY and log into servers easily?

We can create shortcuts for servers that we frequently log into. For example in the Terminal type the following:

alias myserver='ssh'


  • myserver = the name of your alias/shortcut
  • username = a valid user on the server
  • = the server IP address

Now you can ssh to that server by simply typing "myserver". This should prompt you for your password – enter that and you're in!

Use .bash_profile to save aliases

At the moment if you close your Terminal, and then re-open it, your aliases will have been forgotten. So how do we tell Terminal to remember them permanently? The trick is to create a .bash_profile file for your Mac user. This file should exist in your Mac home directory. To create this file follow these steps:

  • Open the Terminal app
  • Type the following:

    vi ~/.bash_profile

  • This will open a new blank file in the "vi" editor
  • Press "i" once – this puts the editor into "insert" mode
  • Put your alias command into the file (same as above) – paste using Ctrl+V, or type it
  • Press the Esc key once
  • Type ":wq" to finish editing the file and save it to disk
  • Now close your Terminal app, and reopen it. Your alias should now be working.

Note: If you have TextMate installed (which I highly recommend) then at the command line just type "mate ~/.bash_profile" (instead of using "vi"). This will open a blank file in TextMate. Then type in the alias command as above and save the file. Then close and reopen the Terminal app.

This was just a quick overview for those who can work out the details from the clues above. Even if you do not use aliases to shortcut logging in to servers they are handy to know about.

Happy aliasing!