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
)。
-
ssh localhost
strong@foreverstrong:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused -
查看 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:~$ -
安装 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:~$ -
启动
strong@foreverstrong:~$ sudo /etc/init.d/ssh start
[sudo] password for strong:
[ ok ] Starting ssh (via systemctl): ssh.service.
strong@foreverstrong:~$ -
停止
sudo /etc/init.d/ssh stop
ssh 默认的端口是 22,可以修改配置文件更改端口,然后重启 ssh 服务即可。(配置文件 /etc/ssh/sshd_config
)
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/