Linux的SSH(Secure Shell Protocol)服务

  在数据传输前,SSH会对需要传输的数据进行加密,保证会话安全与会话中传输数据的安全,SSH客户端还包含一个远程拷贝scp。

1、SSH的结构

SSH服务由服务端软件(openssh)和客户端(SSH、SecureCRT、Xshell)组成,SSH默认使用22端口,SSH服务端是一个守护进程,在后台时刻监听客户端的请求,sshd就是SSH服务端的进程名

补充:(守护进程)

守护进程是一个在后台运行并且不受任何终端控制的进程。Unix操作系统有很多典型的守护进程(其数目根据需要或20—50不等),它们在后台运行,执行不同的管理任务。
用户使守护进程独立于所有终端是因为,在守护进程从一个终端启动的情况下,这同一个终端可能被其他的用户使用。例如,用户从一个终端启动守护进程后退出,然后另外一个人也登录到这个终端。用户不希望后者在使用该终端的过程中,接收到守护进程的任何错误信息。同样,由终端键人的任何信号(例如中断信号)也不应该影响先前在该终端启动的任何守护进程的运行。虽然让服务器后台运行很容易(只要shell命令行以&结尾即可),但用户还应该做些工作,让程序本身能够自动进入后台,且不依赖于任何终端。
守护进程没有控制终端,因此当某些情况发生时,不管是一般的报告性信息,还是需由管理员处理的紧急信息,都需要以某种方式输出。Syslog 函数就是输出这些信息的标准方法,它把信息发送给 syslogd 守护进程。

2、SSH认证类型

(1)基于口令的安全验证,也就是通常所说的账号、密码、端口、IP登录

(2)基于密钥的安全验证

  事先建立一对密钥对,然后将公用的密钥放在服务端,把私有的密钥放在SSH的客户端,最终通过这种密钥验证方式进行加密传输数据。

3、SCP

NAME
     scp - secure copy (remote file copy program)  #安全拷贝

SYNOPSIS
     scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
         [-l limit] [-o ssh_option] [-P port] [-S program]
         [[user@]host1:]file1 ... [[user@]host2:]file2

DESCRIPTION
     scp copies files between hosts on a network.(scp是在网络上通过host之间拷贝文件)  It uses ssh(1) for
     data transfer, and uses the same authentication and provides the
     same security as ssh(1).  Unlike rcp(1), scp will ask for pass-
     words or passphrases if they are needed for authentication.

     File names may contain a user and host specification to indicate
     that the file is to be copied to/from that host.  Local file
   names can be made explicit using absolute or relative pathnames
     to avoid scp treating file names containing ‘:’ as host speci-
     fiers.  Copies between two remote hosts are also permitted.

     When copying a source file to a target file which already exists,
     scp will replace the contents of the target file (keeping the
     inode).

     If the target file does not yet exist, an empty file with the
     target file name is created, then filled with the source file
     contents.  No attempt is made at "near-atomic" transfer using
     temporary files.

-P  端口

-p  保持属性

-r  拷贝目录

4、FTP功能服务sftp

上传:

[root@localhost tmp]# sftp -oport=22 root@192.168.181.129
Connecting to 192.168.181.129...
root@192.168.181.129's password: 
sftp> put /tmp/666 /tmp
stat /tmp/666: No such file or directory
sftp> put /tmp/123.txt /tmp
Uploading /tmp/123.txt to /tmp/123.txt
/tmp/123.txt                                100%    0     0.0KB/s   00:00    

查看上传成功!

下载:

sftp> get /tmp/666 /tmp
Fetching /tmp/666 to /tmp/666
sftp> get /tmp/666 /opt
Fetching /tmp/666 to /opt/666

检查下载到本地成功!

posted @ 2018-02-18 12:43  潇潇、寒  阅读(627)  评论(0编辑  收藏  举报