ubuntu 16.04 desktop + server LTS - secure copy protocol or scp (1)

ubuntu 16.04 desktop + server LTS - secure copy protocol or scp (1)

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.
The SCP is a network protocol, based on the BSD RCP protocol, which supports file transfers between hosts on a network. SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data in transit. A client can send (upload) files to a server, optionally including their basic attributes (permissions, timestamps). Clients can also request files or directories from a server (download). SCP runs over TCP port 22 by default. Like RCP, there is no RFC that defines the specifics of the protocol.
Secure Copy (remote file copy program)
The SCP program is a software tool implementing the SCP protocol as a service daemon or client. It is a program to perform secure copying. The SCP server program is typically the same program as the SCP client. The SCP Server software can be installed on a Regular Machine and be configured to only accept SCP Traffic on port 22 through the firewall for greater security.
Perhaps the most widely used SCP program is the command line scp program, which is provided in most SSH implementations. The scp program is the secure analog of the rcp command. The scp program must be part of all SSH servers that want to provide SCP service, as scp functions as SCP server too.
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@host:directory/TargetFile

Copying file from host:

scp user@host:directory/SourceFile TargetFile
scp -r user@host: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@host: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:
  libllvm4.0 linux-headers-4.10.0-40 linux-headers-4.10.0-40-generic linux-headers-4.10.0-42
  linux-headers-4.10.0-42-generic linux-headers-4.13.0-26 linux-headers-4.13.0-26-generic
  linux-headers-4.13.0-31 linux-headers-4.13.0-31-generic linux-headers-4.13.0-32
  linux-headers-4.13.0-32-generic linux-headers-4.13.0-36 linux-headers-4.13.0-36-generic
  linux-headers-4.13.0-37 linux-headers-4.13.0-37-generic linux-headers-4.13.0-38
  linux-headers-4.13.0-38-generic linux-headers-4.13.0-39 linux-headers-4.13.0-39-generic
  linux-image-4.10.0-40-generic linux-image-4.10.0-42-generic linux-image-4.13.0-26-generic
  linux-image-4.13.0-31-generic linux-image-4.13.0-32-generic linux-image-4.13.0-36-generic
  linux-image-4.13.0-37-generic linux-image-4.13.0-38-generic linux-image-4.13.0-39-generic
  linux-image-extra-4.10.0-40-generic linux-image-extra-4.10.0-42-generic linux-image-extra-4.13.0-26-generic
  linux-image-extra-4.13.0-31-generic linux-image-extra-4.13.0-32-generic linux-image-extra-4.13.0-36-generic
  linux-image-extra-4.13.0-37-generic linux-image-extra-4.13.0-38-generic linux-image-extra-4.13.0-39-generic
  linux-signed-image-4.10.0-40-generic linux-signed-image-4.10.0-42-generic
  linux-signed-image-4.13.0-26-generic linux-signed-image-4.13.0-31-generic
  linux-signed-image-4.13.0-32-generic linux-signed-image-4.13.0-36-generic
  linux-signed-image-4.13.0-37-generic linux-signed-image-4.13.0-38-generic
  linux-signed-image-4.13.0-39-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
  ssh-askpass rssh molly-guard monkeysphere
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 121 not upgraded.
Need to get 633 kB of archives.
After this operation, 5,136 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.4 [38.7 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.4 [335 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 633 kB in 2s (238 kB/s)          
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 586591 files and directories currently installed.)
Preparing to unpack .../ncurses-term_6.0+20160213-1ubuntu1_all.deb ...
Unpacking ncurses-term (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a7.2p2-4ubuntu2.4_amd64.deb ...
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.4) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a7.2p2-4ubuntu2.4_amd64.deb ...
Unpacking openssh-server (1:7.2p2-4ubuntu2.4) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.5-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.5-0ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up ncurses-term (6.0+20160213-1ubuntu1) ...
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.4) ...
Setting up openssh-server (1:7.2p2-4ubuntu2.4) ...
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:0XofsH16QcLBQF1dPQLPgdVlB+oyIUNESIv4NVfaAks root@foreverstrong (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:MAuj2XCewoA99x0ZLrcjERb6xeAmB0ieyANneeZyVOA root@foreverstrong (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:VUzKe2q5N0JGT2+u0Y9LV/UZ3pSuC0W7/YgJPELQy3Y root@foreverstrong (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:5pcBS1I872vfxdF4QQ7QxSBMDhrMI5PZVVHP0QHuaYE root@foreverstrong (ED25519)
Setting up ssh-import-id (5.5-0ubuntu1) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
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)




猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/80467684