October 6, 2024

One of the earlier post explained how to remotely copy multiple files and directories and keep them in sync by using rsync over ssh.

While this is great for transferring files and directories in bulk, what if just a single file or a few files need to be copied quickly? For this, scp (secure copy) can be very useful. It is a remote file copy tool available from Linux Terminal that uses ssh to copy files between different Linux systems.

Suppose a file named readme.txt needs to be copied from local Linux system to a remote server which only accepts ssh connections over a non-standard port like say 2222 instead of the default port 22.

To accomplish this copying, the command that needs to be executed from the local Linux system will be :

scp -P 2222 readme.txt user@remotesystemIP:.

Using scp to remotely copy files

This will first open a ssh connection to the remote system and once authenticated, will copy the local file to that system. The copied file will now be available on remote system in the default directory :

scp2

To copy directly using standard ssh port 22, simply omit the P flag :

scp readme.txt user@remotesystemIP:.

This also can be useful when trying to upload files to the remote server without using FTP and also provides great security.

Happy copying.

By admin

Related Post