SSH is the most secure protocol for accessing servers these days. It provides the highest level of data communication security. The SCP (Secure Copy) command uses the SSH protocol for copying files between remote and local servers.
Download file using SSH
This will connect to example.com server with user “username” and copy the /backup/file.zip file to local system directory /local/dir. To use theis command replace the values as per your environment.
$ scp [email protected]:/backup/file.zip /local/dir
In case SSH is running on different port, You can simply specify the port using
-P option with SCP command.
$ scp -P 2222 [email protected]:/backup/file.zip /local/dir
If your remote server required the private key to connect server, You can use
-i followed by private key file path to connect your server using the SCP command. This can be helpful for AWS servers.
$ scp -i private_key.pem [email protected]:/backup/file.zip /local/dir
Upload file using SSH
You can also upload files to the remote server using SSH protocol using SCP command. Use the following example command for uploading files to SSH server.
$ scp file.zip [email protected]:/remote/dir