找回密码
立即注册
搜索
热搜: Java Python Linux Go
发回帖 发新帖

3449

积分

0

好友

458

主题
发表于 5 小时前 | 查看: 2| 回复: 0

scp 命令 用于安全地在本地与远程主机之间复制文件。如果文件就在当前工作目录,直接给文件名即可;否则就需要写清楚完整路径,包括远程主机名。

把本地文件复制到远程目录:

scp localfile.txt /home/friend/share/

从远程主机拉取文件到当前目录:

scp user@remotehost.com:/var/www/html/remote_file.txt ./

在远程主机之间直接对拷文件:

scp user1@remotehost1.com:/var/www/html/file.txt user2@remotehost2.com:/home/user2/

如果需要复制整个目录(含子目录),记得加上 -r 递归选项:

scp -r user@remotehost.com:/var/www/html/ ./html/

基本用法

日常使用中,可以记忆下面几个最常见的操作模式。

# 将远程文件复制到本地目录
scp user@remotehost.com:/remote/path/to/foobar.md /local/dest

# 将本地文件复制到远程目录
scp /local/path/to/foobar.md user@remotehost.com:/remote/path

# 使用密钥文件认证(和 ssh 用法一致)
scp -i /path/to/key/file /local/path/to/foobar.md user@remotehost.com:/remote/path

以上就是 SCP 命令最常用的几种场景,掌握它们基本就能覆盖日常文件拷贝需求。更多 Linux 实战技巧,欢迎常来云栈社区逛逛。




上一篇:Linux 桌面为何不稳定、体验差?聊聊硬件、生态与市场三大死穴
下一篇:GPT Image 2登顶后,AI产品主图设计已迈入工业级生产力时代
您需要登录后才可以回帖 登录 | 立即注册

手机版|小黑屋|网站地图|云栈社区 ( 苏ICP备2022046150号-2 )

GMT+8, 2026-4-25 09:00 , Processed in 0.984120 second(s), 41 queries , Gzip On.

Powered by Discuz! X3.5

© 2025-2026 云栈社区.

快速回复 返回顶部 返回列表