Making your ssh life paradise – Using a config file

The config file can automate many tedious processes.

Eg: You wish to scp a file from the current machine to a host like XDA, using a specific identity key. Of course you can use ssh-add to add the key, but it may not be recognized each reboot.

The usual command is like

scp -i ~/.ssh/path_to_keyfile sourcefilename [email protected]:~/targetpath

Once a .config file is set up, your new command becomes:

scp sourcefile xda:target


Create a text file in ~/.ssh/config:

[email protected]:~$ cat /home/droidzone/.ssh/config                                                                                                                    
Host bitbucket                                                                                                                                               
    IdentityFile ~/.ssh/bitbucket                                                                                                                                     
Host xda                                                                                                                                                              
     User droidzone                                                                                                                                                   
     IdentityFile ~/.ssh/xdamachine_key_openssh_pvt                                                                                                                   
     ServerAliveInterval 30                                                                                                                                           
     ServerAliveCountMax [email protected]:~$

Here, as you can see, I’ve added two hosts. One is my Bitbucket account, and I’ve specified a key file for authentication.

For XDA, I’ve given it a label “xda”, specified the build server username and hostname, specified an identity file, and a timeout interval.

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.