Secure Shell (SSH) is a protocol which is used to access Linux servers remotely. In short, we can say it allows the secure exchange of data between two computers. Commonly port 22 is used to connect one computer to another
SCP command is uses the SSH protocol for copying the file between remote and local machine.
Download File Using SSH
We can use SCP command to download the from remote server. For example I am going to download a file called “test.tar.gz” which is located on remote server example.com /opt directory in our local system /var directory. You can replace the values as per your requirement.
# scp [email protected]:/opt/test.tar.gz /var/
If your SSH service running on different port (2022) then you can simply mention the port using –P option with SCP command.
# scp -P 2022 [email protected]:/opt/test.tar.gz /var/4
In case your remote server require key base authentication such as public and private key then you can use –i option followed by private key file to connect your remote server using the SCP command.
# scp -i private_key.pem [email protected]:/opt/test.tar.gz /var/
Uploading File Using SSH
Now you can also upload a file to the remote server using SSH protocol using SCP command. Follow the below command to upload the file on remote SSH server.
# scp /var/test.tar.gz [email protected]:/var/www/html/