SCP(Secure Copy Protocol)是一种用于在本地和远程计算机之间安全地复制文件的命令行工具,以下是一些常用的scp命令和技巧:

scp攻略,

1、从本地复制文件到远程服务器:

scp [options] source_file user@remote_host:destination_path

将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下:

scp file.txt user@192.168.1.100:/home/user/

2、从远程服务器复制文件到本地:

scp [options] user@remote_host:source_file destination_path

将远程服务器192.168.1.100的用户user的/home/user/file.txt复制到本地目录/home/local_user下:

scp攻略,
scp user@192.168.1.100:/home/user/file.txt /home/local_user/

3、使用端口号(默认端口为22):

scp P port_number source_file user@remote_host:destination_path

使用端口号2222将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下:

scp P 2222 file.txt user@192.168.1.100:/home/user/

4、使用密钥进行身份验证:

scp i private_key_file source_file user@remote_host:destination_path

使用私钥文件id_rsa将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下:

scp攻略,
scp i id_rsa file.txt user@192.168.1.100:/home/user/

5、递归复制整个目录:

scp r [options] source_directory user@remote_host:destination_path

将本地目录dir复制到远程服务器192.168.1.100的用户user的/home/user目录下:

scp r dir user@192.168.1.100:/home/user/

6、显示传输过程中的进度:

scp l [options] source_file user@remote_host:destination_path

将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下,并显示传输进度:

scp l file.txt user@192.168.1.100:/home/user/

7、保留文件属性(如时间戳、权限等):

scp p [options] source_file user@remote_host:destination_path

将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下,并保留文件属性:

scp p file.txt user@192.168.1.100:/home/user/

8、使用代理进行连接:

scp o "ProxyJump user@proxy_host" source_file user@remote_host:destination_path

通过代理服务器192.168.1.101将本地文件file.txt复制到远程服务器192.168.1.100的用户user的/home/user目录下:

scp o "ProxyJump user@192.168.1.101" file.txt user@192.168.1.100:/home/user/

这些是一些常用的scp命令和技巧,可以根据实际需求进行调整和组合。