Linux(二十六) 深入了解基础服务OPENSSH

目录

 

一、SSH基础知识

   1.1.ssh协议

   1.2.OpenSSH

二、openssh服务的配置文件解析

  2.1.安装方式

 2.2.配置文件位置

 2.3.查看修改配置

 2.4.设置黑白名单 (服务端配置)

 2.5 重启服务

 2.6.链接服务端通信

三、免密登录

3.1.加密算法

3.1.2.对称加密

3.1.3.非对称加密

3.2 如图所示如何加密解密

3.3.免密制作过程

3.3.1.密钥存放位置

3.3.2.免密登录验证

四、SCP命令

五、SFTP命令

六、TCP Wrappers

   6.1.TCP的保护机制

   6.2.访问控制策略的配置文件

   6.3.策略格式

   6.3.通过以下方式,查看是否支持TCP的限制

   6.4.修改TCP允许及策略配置


一、SSH基础知识

   1.1.ssh协议

  •     是一种安全通道协议

  •     对通信数据进行了加密处理,用于远程管理

   1.2.OpenSSH

  •      服务名称:sshd
  •      服务端主程序:/usr/sbin/sshd
  •      服务端配置文件:/etc/ssh/sshd_config

 

二、openssh服务的配置文件解析

 

  2.1.安装方式

yum -y install openssh-server

 2.2.配置文件位置

rpm -qc openssh-server

 2.3.查看修改配置

 客户端配置文件:/etc/ssh/ssh_config

å¨è¿éæå¥å¾çæè¿°

注意:UseDNS yes 开启反向解析 开启后会导致服务自动去找DNS解析服务器。
            /var/run/sshd.pid文件为存放sshd服务的PID进程号,如果删除,如同kill -9 进程号
            最大登录次数最好修改到客户端和服务端都一致,不然登录时以设置最小登录次数为准

#配置文件修改后,需要进行检查
sshd -t

2.4.设置黑白名单 (服务端配置)

 

设置只允许tom 使用某个ip地址登录

2.5 重启服务

systemctl restart sshd

2.6.链接服务端通信

#1.端口为默认端22
ssh root@192.168.1.22

#2.端口修改为10022,而客户端没有跟着变化
ssh -p 10022 root@192.168.1.22

#3.端口修改为10022 ,客户端也跟着修改为10022
ssh root@192.168.1.22

三、免密登录

3.1.加密算法

3.1.2.对称加密

       采用单钥密码系统的加密方法,同一个密钥可以同时用作信息的加密和解密,这种加密方法称为对称加密,由于其速度快,对称性加密通常在消息发送方需要加密大量数据时使用。
       弊端:公钥容易被劫持,信息被其他人解密盗取

3.1.3.非对称加密

       非对称加密算法需要两个密钥:公开密钥和私有密钥。公钥与私钥是一对,如果用公钥对数据进行加密,只有用对应的私钥才能解密。因为加密和解密使用的是两个不同的密钥,所以这种算法叫作非对称加密算法。

3.1.4.非对称加密解密过程
SSH:
       客户端和服务端各产生一对公钥和私钥,第一次连接,客户端发送自己的公钥给客户端,服务端保存客户端的公钥。然后客户端发起连带公钥的连接请求,服务端根据之前客户端发送的公钥进行对比,如果一致,服务端会拿客户端的公钥加密一段随机数据发回给客户端,客户端拿自己的私钥解密这个数据,发送会服务端。然后服务端收到客户端解密的数据发现就是自己之前加密的数据,这时就认为此客户端是受信任的,连接建立。

RSA:
       有发送方A和接受方B ,A通过B公钥加密发送给B,B通过自己的私钥解开。B也可以通过A公钥加密发送给A,A通过自己的私钥解开。但是由于公钥在网上容易流传,所以不安全。所以A通过自己的私钥在外做一层签名,证明是来自A的消息,而私密不可再往上流传,所以增加了安全性。

3.2 如图所示如何加密解密

 

 

 

 

 

3.3.免密制作过程

#第一步:在客户端生成公钥和私钥
   [root@localhost ~]# ssh-keygen -t RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #加密后密钥存放位置
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):  # 设置密码,此处不做设置
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:AYfSQw6qqBnfKYD8UMS6fOWni3YCMTY+UXtVa11t4WY root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|  ...oo.o.   ....|
|  .+.o++  o . .o |
|  +...o..o .  .E |
|+O.. o  ..    o  |
|Xo* +   S        |
|.@oo o .         |
|o *.o o          |
|   +.o           |
|  ..o..          |
+----[SHA256]-----+


#第二步:将公钥传输到服务端
ssh-copy-id root@192.168.1.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:/xHHOcYyLpVrBwce3DDn32fz9HhOlU4Di1NhbvP3Je4.
ECDSA key fingerprint is MD5:1e:e1:e3:87:b0:12:de:18:44:77:c1:38:92:b8:66:77.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.20's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.1.20'"
and check to make sure that only the key(s) you wanted were added.

3.3.1.密钥存放位置

查看 /root/.ssh/

查看 cat /root/.ssh/authorized_keys

3.3.2.免密登录验证

四、SCP命令

#把本地文件传到对端opt文件夹下(上传)
scp ks.cfg root@192.168.1.20:/opt 
#把对端的文件传到本地(下载)     
scp root@192.168.1.20:/opt/anaconda-ks.cfg /tmp   
#-r 对目录使用  -p 对属性 
scp -rp  
#端口修改后   -P(大写的P)
scp -P 10022 -rp xx/ root@192.168.1.20:/opt  

五、SFTP命令

 

[root@localhost ~]# sftp root@192.168.1.20 #通过sftp连接
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:/xHHOcYyLpVrBwce3DDn32fz9HhOlU4Di1NhbvP3Je4.
ECDSA key fingerprint is MD5:1e:e1:e3:87:b0:12:de:18:44:77:c1:38:92:b8:66:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.20' (ECDSA) to the list of known hosts.
root@192.168.1.20's password: 
Connected to 192.168.1.20.
sftp> 
sftp> 
sftp> 
sftp> ls #查看连接后1.20的服务器的内容
-e                                       0                                        117015233?spm=1001.2014.3001.5501        117035614?spm=1001.2014.3001.5501        20210505-215905.httpd.tar.gz             
Playtes.sh                               anaconda-ks.cfg                          cc.sh                                    fa2                                      fw.sh                                    
httpd-ym.sh                              httpd-youh.sh                            httpd-yum.sh                             httpd.sh                                 httpd.sh.gz                              
httpd.tar.gz                             initial-setup-ks.cfg                     network.sh                               networkTest.sh                           read1                                    
sed.txt                                  test.txt                                 test1.sh                                 test1.sh.bz2                             test11.sh.bz2                            
thread2.sh                               thread3.sh                               threadT.sh                               threadTH.sh                              xx.sh                                    
下载                                   公共                                   图片                                   文档                                   桌面                                   
模板                                   视频                                   音乐                                   
sftp> lls # 查看本机的内容
0				   20210505-215905.httpd.tar.gz  -e	httpd.sh      httpd-ym.sh    initial-setup-ks.cfg  Playtes.sh  test11.sh.bz2  test.txt	  threadTH.sh  公共  图片  音乐
117015233?spm=1001.2014.3001.5501  anaconda-ks.cfg		 fa2	httpd.sh.gz   httpd-youh.sh  network.sh		   read1       test1.sh       thread2.sh  threadT.sh   模板  文档  桌面
117035614?spm=1001.2014.3001.5501  cc.sh			 fw.sh	httpd.tar.gz  httpd-yum.sh   networkTest.sh	   sed.txt     test1.sh.bz2   thread3.sh  xx.sh        视频  下载

sftp> put /root/Playtes.sh /root/ #将本机的Playtest.sh 文件上传到服务端
Uploading /root/Playtes.sh to /root/Playtes.sh
/root/Playtes.sh 
sftp> get /root/network.sh  /root/ #从服务端下载文件
Fetching /root/network.sh to /root/network.sh
/root/network.sh                                  

六、TCP Wrappers

   6.1.TCP的保护机制

       方式1:通过tcpd程序对其他服务程序进行包装
       方式2:由其他服务程序调用libwrap.so.*链接库

   6.2.访问控制策略的配置文件

[root@localhost ~]# vim /etc/hosts.allow     #设置允许策略的配置文件
[root@localhost ~]# vim /etc/hosts.deny      #设置拒绝策略的配置文件

6.3.策略格式

  • 服务程序列表:客户端地址列表
  • 服务程序列表

多个服务以逗号分隔,ALL表示所有服务

  • 客户端地址列表

      多个地址以逗号分隔,ALL表示所有地址
      允许使用通配符﹖和*
      网段地址,如192.168.4.或者192.168.4.0/255.255.255.0
      区域地址,如.benet.com
 

 

6.3.通过以下方式,查看是否支持TCP的限制

6.4.修改TCP允许及策略配置

[root@localhost ~]# vim /etc/hosts.allow
sshd:192.168.1.20 #放开192.168.1.20
[root@localhost ~]# vim /etc/hosts .deny
sshd:ALL  #拒绝所有

 

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值