When you use the SSH config file, the scp
command becomes much simpler. You can skip typing the private key file path, remote server user name and IP address.
Only three sets of information are needed for the command.
-r
option.)For a better understanding, please go through the following practice section.
The following are the paths of the file to be transferred and the destination directory.
Note: For this practice, open two terminals (command lines). One for a local operation and another one for a remote operation.
Create a sample file for transferring to the remote server.
For this operation, use the local terminal that is not connected to the remote server.
cd ~/dir_ch7_local
touch sample2.txt
Run the scp
command with the source file path and destination directory path.
scp sample2.txt ssh_test:dir_ch7_remote
sample2.txt 100% 0 0.0KB/s 00:00
If you set a passphrase for the private key, you need to enter the passphrase to move forward.
Using the terminal connected to the remote server, check if the file is successfully transferred.
ls dir_ch7_remote
You can see that the file was successfully transferred.
sample.txt sample2.txt
Only three sets of information are needed for the command.
-r
option.)For a better understanding, please go through the following practice section.
The following are the paths of the directory to be transferred and the destination directory.
Note: This practice can be done only with the local terminal.
Run the command below to create a new directory for receiving a directory from the remote server.
cd ~
mkdir dir_ch7_local_2
Run the scp
command with the -r
option
scp -r ssh_test:dir_ch7_remote dir_ch7_local_2
sample.txt 100% 0 0.0KB/s 00:00
sample2.txt 100% 0 0.0KB/s 00:00
If you set a passphrase for the private key, you need to enter the passphrase to move forward.
Check if the directory is successfully transferred from the remote server to the local computer.
ls dir_ch7_local_2
You can see that the file was successfully transferred.
dir_ch7_remote
When you use the SSH config file, the scp
command becomes much simpler. You can skip typing the private key file path, remote server user name and IP address.
Only three sets of information are needed for the command.
-r
option.)For a better understanding, please go through the following practice section.
The following are the paths of the file to be transferred and the destination directory.
Note: For this practice, open two terminals (command lines). One for a local operation and another one for a remote operation.
Create a sample file for transferring to the remote server.
For this operation, use the local terminal that is not connected to the remote server.
cd ~/dir_ch7_local
touch sample2.txt
Run the scp
command with the source file path and destination directory path.
scp sample2.txt ssh_test:dir_ch7_remote
sample2.txt 100% 0 0.0KB/s 00:00
If you set a passphrase for the private key, you need to enter the passphrase to move forward.
Using the terminal connected to the remote server, check if the file is successfully transferred.
ls dir_ch7_remote
You can see that the file was successfully transferred.
sample.txt sample2.txt
Only three sets of information are needed for the command.
-r
option.)For a better understanding, please go through the following practice section.
The following are the paths of the directory to be transferred and the destination directory.
Note: This practice can be done only with the local terminal.
Run the command below to create a new directory for receiving a directory from the remote server.
cd ~
mkdir dir_ch7_local_2
Run the scp
command with the -r
option
scp -r ssh_test:dir_ch7_remote dir_ch7_local_2
sample.txt 100% 0 0.0KB/s 00:00
sample2.txt 100% 0 0.0KB/s 00:00
If you set a passphrase for the private key, you need to enter the passphrase to move forward.
Check if the directory is successfully transferred from the remote server to the local computer.
ls dir_ch7_local_2
You can see that the file was successfully transferred.
dir_ch7_remote