SSH and SCP Two Important Linux Commands

By | February 5, 2011

ssh is a really useful command to interact with other servers. It basically allows you to get into another linux machine on which you have a user account. SCP command on the other hand allows you to transfer file securely from one machine to another using ssh. So, before you learn about scp it’s important that you should learn about ssh. So, here we go…

Here is the syntax used while connecting to another machine with a user account using ssh. In this case, I consider that the port number of the other machine is set to default port 22.

ssh username@ip-address-of-othermachine

example: ssh linux@

If the other machine is not using the default port number then you might have to use the following syntax.

ssh -p portnumber username@ip-address-of-othermachine.

example: ssh -p 6060 linux@

Note ‘p’ is small letter here and 6060 is the port number of the other machine. If you want to change the ssh port number of your machine for security reasons, then as a root user edit /etc/ssh/sshd_conf and change the port number to 6060 and restart ssh. You can reastart ssh like this.

/etc/init.d/ssh restart

Now, if you want to transfer a file from one system to another securely, then we use scp. Here is how scp is used.

scp -P portnumber transerred-file-filename username@ip-address:/destination-path/

example: scp -P 6060 filename linux@

Note: ‘P’ is capital letter here. The files can be transferred only for the directories for which the user holds the permissions for. However, root user of remote machine can transfer files to any location he/she wanted.

If you want to transfer the files from remote machine to local machine, here is how you can do it.

scp -P portnumber username@ip-address:/file-location/ /file-location-local-macnone/

example: scp -P 6060 linux@ /home/

Hope you liked this tutorial. I know most of the advanced users know this stuff, but I created this one for the beginners and my further reference.

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!

Leave a Reply

Your email address will not be published. Required fields are marked *