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"



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

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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy