Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im relatively new to Ubuntu, Im wondering how easy it is to write what I think is called a shell script to make tasks a little easier.

For example I frequently connect to a server - ssh -p 123 me@mysite.com

Can and how could I shorten this to a shorter command like "mysite" or "ssh mysite"


share|improve this question

3 Answers 3

up vote 6 down vote accepted

Alias is a quick and easy way, but a more secure one is to set up an ssh profile. In your ~/.ssh/config, put

Host mysite
Port 123
Hostname mysite.com
User me

Then you connect by just typing

ssh mysite
share|improve this answer
Perfect, thanks for your help. –  jjodat Apr 6 '10 at 13:00

For this particular case, you can add the following to the ssh config file (in ~/.ssh/config):

Host mysite.com
User me
Port 123

Host mysite2.com
User otherme
Port 2222

This will shorten the command to ssh mysite.com, which is not bad, and will also work with other programs relying on ssh (scp, sftp, many version control systems, etc)

You could go further and add a shorter hostname in /etc/hosts:

123.456.1.1   mysite   mysite.com

then replace mysite.com by mysite in the other places.

share|improve this answer

Maybe an alias in your shell is sufficient : alias mysite='ssh -p 123 me@mysite.com' Put that in your .bashrc (if your shell is the bash) and reload it by source .bashrc

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.