Copy files remotely in Linux environment, scp command

In the Linux environment, if we want to copy files to another environment, you may find it troublesome, because many times we connect to the LInux environment remotely, and there is no way to directly copy files to the local desktop. At this time, you can use the scp command to remotely copy the file.
scp is secure copy, a command used to copy files remotely under linux.
Sometimes we need to obtain a certain file on the remote server. The server is neither configured with an ftp server nor shared. When the file cannot be obtained through conventional means, we only need to use a simple scp command to achieve the goal.

1. Copy the local file to the remote server

#scp /home/administrator/news.txt      [email protected]:/etc/squid
  /home/administrator/ 本地文件的绝对路径
  news.txt 要复制到服务器上的本地文件
  root 通过root用户登录到远程服务器(也可以使用其他拥有同等权限的用户)
  192.168.6.129 远程服务器的ip地址(也可以使用域名或机器名)
  /etc/squid 将本地文件复制到位于远程服务器上的路径

2. Copy the files on the remote server to this machine

#scp [email protected]:/usr/local/sin.sh /home/administrator
  remote 通过remote用户登录到远程服务器(也可以使用其他拥有同等权限的用户)
  www.abc.com 远程服务器的域名(当然也可以使用该服务器ip地址)
  /usr/local/sin.sh 欲复制到本机的位于远程服务器上的文件
  /home/administrator 将远程文件复制到本地的绝对路径

Pay attention to two points:
  1. If the firewall of the remote server has special restrictions, scp will use a special port. The specific port depends on the situation. The command format is as follows:
  #scp -p 4588 [email protected]:/usr/ local/sin.sh /home/administrator
  2. When using scp, pay attention to whether the user used has the permission to read the corresponding files on the remote server.
  like:

# scp /var/log/sql-slow-queries.log [email protected]:/root
  把本地 /var/log/sql-slow-queries.log 这个文件copy到1.50上面/root 目录下面

Guess you like

Origin blog.csdn.net/weixin_42648692/article/details/127245130