Secure Copy Protocol or SCP

Secure Copy Protocol or SCP

Secure copy protocol or SCP is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. SCP commonly refers to both the Secure Copy Protocol and the program itself.

Some SSH implementations provide the scp2 program, which uses the SFTP protocol instead of SCP, but provides the very same command line interface as scp. scp is then typically a symbolic link to scp2.

Typically, a syntax of scp program is like the syntax of cp (copy).

Copying file to host:

复制代码
scp SourceFile user_name@host_ip:directory/TargetFile

Copying file from host:

复制代码
scp user_name@host_ip:directory/SourceFile TargetFile
scp -r user_name@host_ip:directory/SourceFolder TargetFolder

Note that if the remote host uses a port other than the default of 22, it can be specified in the command. For example, copying a file from host:

复制代码
scp -P 2222 user_name@host_ip:directory/SourceFile TargetFile

As the Secure Copy Protocol implements file transfers only, GUI SCP clients are rare, as implementing it requires additional functionality (directory listing at least). For example, WinSCP defaults to the SFTP protocol. Even when operating in SCP mode, clients like WinSCP are typically not pure SCP clients, as they must use other means to implement the additional functionality (like the ls command). This in turn brings platform-dependency problems.

Ubuntu 默认并没有安装 ssh 服务程序 (openssh-server),默认安装了 ssh 客户程序 (openssh-client)。

  1. ssh localhost

    strong@foreverstrong:~$ ssh localhost
    ssh: connect to host localhost port 22: Connection refused

  2. 查看 ssh 服务是否启动 / 运行

    strong@foreverstrong:~ ps -e | grep ssh strong@foreverstrong:~
    strong@foreverstrong:~ sudo ps -e | grep ssh strong@foreverstrong:~
    strong@foreverstrong:~ sudo service ssh start Failed to start ssh.service: Unit ssh.service not found. strong@foreverstrong:~

  3. 安装 ssh 服务

    strong@foreverstrong:~ sudo apt-get install openssh-server Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: ... strong@foreverstrong:~

  4. 启动

    strong@foreverstrong:~ sudo /etc/init.d/ssh start [sudo] password for strong: [ ok ] Starting ssh (via systemctl): ssh.service. strong@foreverstrong:~

  5. 停止

    sudo /etc/init.d/ssh stop

ssh 默认的端口是 22,可以修改配置文件更改端口,然后重启 ssh 服务即可。(配置文件 /etc/ssh/sshd_config)

References

1\] Yongqiang Cheng,

相关推荐
yuxinaibiancheng16 天前
yunedit-ssh跟winscp对比有什么好处
ssh·sftp·scp
予枫的编程笔记21 天前
【Linux进阶篇】SSH密钥认证保姆级实操:告别密码登录,远程连接更安全高效
linux·ssh·scp·rsync·免密登录·ssh-keygen·密钥认证
七夜zippoe1 个月前
gRPC高性能RPC框架实战:从Protocol Buffers到流式传输的完整指南
网络·python·网络协议·rpc·protocol
晚风吹人醒.2 个月前
SSH远程管理及访问控制
linux·运维·ssh·scp·xshell·访问控制·远程管理
yaoty3 个月前
深入理解MCP:AI 应用与外部世界的桥梁
ai·protocol·mcp
siriuuus5 个月前
Linux ssh/scp/sftp命令使用及免密登录配置
linux·ssh·sftp·scp
冲凉丶7 个月前
Linux中scp命令传输文件到服务器报错
linux·服务器·scp·传输文件
大熊猫侯佩9 个月前
Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(上)
swift·协议·protocol·coredata·协议扩展·托管基类·协议关联类型
大熊猫侯佩9 个月前
Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)
swift·协议·protocol·coredata·协议扩展·基类子类·类型不匹配