Setting Up A SSH Trusted Connection & Bash Alias To Speed Up Automated Scripts
Need to automate some scripts? Tired of constantly entering ssh user@server.address, then the password? Having a trusted connection can drastically improve productivity if it is used in the correct conditions. If you’re using a public machine, then this is NOT SMART. If you’re using a machine that anyone else has access to, then again, this is not a solution, and shouldn’t be considered as an option.
However, if you have a private machine that you keep secure, and you want to setup some quick access to remote server, setup automatic backup scripts, take snapshots of drive data structures, then this will get you going quick!
Here’s the quick steps to get you on the road to automated scripts:
On your box, generate the ssh public key:
- On your box, generate the ssh public key:
- ssh-keygen -t dsa
- when it asks for a passphrase, just hit return.
- go to your home directory, then type, cd .ssh
- cat id_dsa.pub – this is the generated ssh key you will give to the remote host.
- On the remote host, as username@yourdomain.com
- vi .ssh/authorized_keys
- insert your ssh public key – the text from the .ssh/id_dsa.pub file on your box
- make sure the text you copy is on a single line (it will not work if it’s not on a single line)
- verify trusted SSH
- In a terminal window type, ssh -Y username@yourdomain.com
If you want to take this one step further, and make it ever ‘faster’, setup an alias in the .bashrc file.
just add this line to your .bashrc in your home dir, and do not forget to close/reopen your terminal after you add this line, or you will not see it work (the config file will not be loaded):
alias home=’ssh username@yourdomain.com’
at the command prompt in terminal (after you’ve remembered to close & reopen it!) is type “home” and hit the enter key.
So, now you can type one word, get to your remote server in seconds rather than hassling through typing out the same info over and over.
One of your first tasks should be to write a backup script to backup your critical files like your .bashrc!
Enjoy,
Need a “Pick-Me-Up?”





August 9th, 2010 at 8:21 am
I want to hit the remote machine’s alias command on ssh, So how it is possible.
Like
On remote machine the alias command is something like, greet is command
alias greet = echo “Hi Naveen”
ssh user@ “greet”
the output should come like- Hi. Even here I don’t care about permissions.