Linux ssh, sftp, scp commands to transfer files remotely

linux ssh, sftp, scp commands to transfer files remotely linux ssh, sftp, scp commands to transfer files remotely

The following experimental data are all manually tested, not copied, so they are authentic and reliable. They are also some commands that I often use in my work. Share them and let everyone learn together. The operating environment of the system is Centos 7.3 64 *2, the two machines are both in the public network and the IP addresses are

A:223.5.5.5

B:223.6.6.6

sftp is an interactive file transfer program

It is similar to the ftp transmission protocol and belongs to ssh, but it performs encrypted transmission and has higher security than FTP.

sftp usage

If the port of the server is not the default 22, please add -P port number after sftp.

# sftp [email protected]
The authenticity of host ‘223.6.6.6 (223.6.6.6)’ can’t be established.
ECDSA key fingerprint is SHA256:Hl/dKTFzL4lOlF8DIG5itaV4OAsZunC2AWlFGLjLfsg.
Are you sure you want to continue connecting (yes/no)? yes【输入yes回车】
Warning: Permanently added ‘223.6.6.6’ (ECDSA) to the list of known hosts.
[email protected]'s password: [Enter the root password of 223.6.6.6 and press Enter]
Connected to 223.6.6.6.
sftp>

Download the 223.6.6.6 server file to the home directory of 223.5.5.5;

sftp> get /var/www/renwole.txt /home/

Upload the 223.5.5.5 server file to the mnt directory of the 223.6.6.6 server;

sftp> put /home/renwole.txt /mnt/

If you don't know what the directory of the remote host looks like, the ls command can list the current directory of the 223.6.6.6 server. E.g:

sftp> ls //same as viewing local operation command
sftp> pwd //Query the current working directory of 223.6.6.6

You can use cd to change the path, and use cd to change the local path. For example;

sftp> cd

If used to modify server files, you can use ssh connection, for example:

# ssh [email protected]
[email protected]'s password: [Enter the B server password and press Enter to enter the interior]

If you want to quit, for example:

# exit //Exit the machine and return to your original machine interface.

scp has the same authentication mechanism as ssh, so that two machines can securely copy files remotely

scp can be summarized as: scp -P port file path username@host address:remote directory

If you want to copy local files to another ssh terminal, you can use the following command;

# scp /renwole/mariadb.tar.gz [email protected]:/renwole123/
[email protected]'s password:【Enter password and press Enter】
mariadb.tar.gz 8% 37MB 1.3MB / s 05:29 ETA

If you do the reverse operation, copy the files of the remote host to the current system, the operation command is as follows;

# scp [email protected]:/renwole123/mariadb.tar.gz /renwole

If you want to copy the folder and all the files in the folder, add the parameter -r If your port number is not 22, then you need to add a -P (case-sensitive) port number after scp. It is recommended to add the -C option, because it enables the compression function of SSH; the transfer speed is faster, e.g.

# scp -P 6632 -C /renwole/mariadb [email protected]:/renwole123/

In fact, I personally recommend using scp, which is fast, stable and safe.

The original text comes from: https://www.linuxprobe.com/ssh-sftp-scp.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324923001&siteId=291194637