scp Command in Linux: Copy Remote Files Securely over SSH
The scp command in Linux copies files to/from remote computers using the SSH protocol, securely.
scp can be used to send or receive files, depending on whether the source or destination is a remote copy path.
A remote path has the following syntax: user@address:/directory.
Examples:
To copy the local file /home/uira/arquivo to servidor.com using the uira user credentials:
$ scp /home/uira/arquivo [email protected]:/tmp
To copy the file /home/www/arquivo from servidor.com to the local directory /home/uira:
$ scp [email protected]:/home/www/arquivo /home/uira
You can also use "." to represent the current directory:
$ scp [email protected]:/home/www/arquivo .
Wildcards can also be used:
$ scp /home/uira/*.js [email protected]:/var/www/html/js
It is important that the user has write permissions in the destination directory.
scp can be used with the following options:
- -C Compresses files during transfer;
- -p Preserves file permissions and access and modification dates;
- -r Recursively copies subdirectories and files;
scp can also be used to make copies directly between two remote machines:
$ scp -rcv usuario1@maquina1:/arquivos usuario2@maquina2:/backup
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Liked it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.