SSH is the most secure protocol for accessing remote servers. It provides the highest level of end-to-end data security over communication channels. The SCP (Secure Copy) command uses the SSH protocol for copying files between remote and local servers.

Advertisement

The remote server must have a running SSH server. This tutorial will help you to understand download and upload files over SSH protocol.

Download file over SSH Protocol

Here are some useful examples for downloading files from the remote system over SSH protocol.

  • 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 username@example.com:/backup/file.zip /local/dir 
    
  • If the SSH is running on a non-standard port, You can specify the port using -P option with SCP command.
    scp -P 2222 username@example.com:/backup/file.zip /local/dir 
    
  • If your remote server required a private key to connect server, You can use -i followed by a private key file path to connect your server using the SCP command. This can be helpful for AWS servers.
    scp -i private_key.pem username@example.com:/backup/file.zip /local/dir 
    

Upload file using SSH

You can also upload files to the remote server using SSH protocol using the SCP command. Use the following example command for uploading files to the SSH server.

scp file.zip username@example.com:/remote/dir 

Similarity you can use -P switch to define port of the SSH server and -i to define private key for the user authentication.

Conclusion

In this tutorial, you have learned about transferring files between two systems over the SSH protocol.

Share.

4 Comments

Leave A Reply


Exit mobile version