VPS 搬家,传送文件的方法: sudocp
原来有一个 VPS,新买了一个 VPS,怎么把重要文件、数据从原 VPS 传送到新 VPS?这里介绍一个很好的 bash 脚本工具 sudocp
服务器之间不需要相互访问。要复制的文件不会写入任一服务器上的临时文件,也不会写入运行脚本的计算机上
例子
sudoscp from to /home/usrName/public /etc/overtls/config.json
Enter Password:
/home/usrName/public
/etc/overtls/config.json
上面示例中传送了一个目录、一个文件
运行 sudocp 命令行后,会让你输入两个 VPS 的相同 sudo 密码,然后后就会在屏幕上显示传送成功的文件的路径
在 ~/.ssh/config
中定义二个 Host
,示例:
Host from
HostName 192.191.190.189
User loginName
Port 22
IdentityFile path/to/rsa
Host to
HostName 154.153.152.151
User loginName
Port 22
IdentityFile path/to/rsa
IdentitiesOnly yes
from
代旧原先的 VPS, to
代表新的 VPS
loginName
是你 ssh 登录 VPS 的用户名,两个 VPS 可以不同
Windows 下安装 Msys2 也可以运行这个 bash 脚本
使用前提条件
- 两台服务器都需要通过无密码 ssh(使用公钥认证)进行访问
- 两台服务器都需要安装 tar 和 sudo
- 两台服务器的 sudo 密码需要相同
There you go! If there's anything else you need, feel free to ask!
About
sudoscp is a short script to allow copying files that are not readable or writable by your user between machines where you have sudo access but don't have access to log in as root over ssh. The servers does not need to be able to reach each other. The files to copy are not written to temporary files on either servers nor on the box the script is running from. Example
sudoscp server1.example.com server2.example.com /tmp/myfile /tmp/myfile2 Enter Password: /tmp/myfile /tmp/myfile2
Prereq Both servers need to be accessible by passwordless ssh (using public key auth). Both servers need to have tar and sudo installed. The sudo password needs to be the same on both servers
相关内容
2024-12-22