Tuesday 8 October 2013

Quick scp and ssh using ssh_config file

Its good to use a key and different port number to access of our server. So to make our life easy we use the ".ssh/config" file to set the setting.

Using the .ssh/config we can connect to remote server, without using the ssh key option like -p <port#> -i <key>.

A sample of the ssh config file is:

Host hostname_of_your_wish
HostName OriginalHostDNS/IP_address
Port ThePortNumbre_Where_ssh_runs
User UsernameToLogin
IdentityFile PathToTheKeyFile

Example:

Host weserver1
HostName webserver1.example.com
Port 9876
User amitmund
IdentityFile LiveExample.pem


Once you set this kind of config file, next time you just time to "ssh webserver1" and you are in the webserver1.example.com host.

How to use the scp using the same config file.

The option is -F <filename>

so, you can do:

scp -F ~/.ssh/config testFile webserver1:~

The above command will copy your testFile to the webserver1.example.com site.

I have added an alias of scp command to my profile file that, even I don't have to type the -F options. Following setting I have added in my alias:

# -r Recursively copy entire directories.  Note that scp follows symbolic links encountered in the tree traversal. [ Follow Symlink ]
# -F ssh_config
alias='/usr/bin/scp -r -F ~/.ssh/config'

And that help me a lot.




No comments:

Post a Comment