ssh以及ssh的key认证


1.什么是openssh

是一个提供远程访问控制的软件。

 

2.通过ssh远程登陆

ssh username@IP  #登陆

louout           #登出 

wKioL1fP2MCQ4wcLAAFQgJ_mgnc851.png

2.sshkey认证

key分为公与私      # 相当于锁  相当于钥匙

1) 创建key

ssh-keygen  #生成key

 

[root@localhost Desktop]# ssh-keygen             #创建key

Generating public/private rsa key pair.             #创建过程

Enter file in which to save the key (/root/.ssh/id_rsa):  #生成key的储存位置,建议使用默认

Enter passphrase (empty for no passphrase):         #key的密码,可以为空

Enter same passphrase again:                    #重复key的密码

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:

8c:dd:ed:96:49:73:db:e8:38:0a:7c:fc:25:90:c4:42 root@localhost

The key's randomart p_w_picpath is:

+--[ RSA 2048]----+

|        E        |

|       . .       |

|        . o      |

|       + + o     |

|      . S + + .  |

|       . . + = + |

|        o o * + .|

|         o o.=   |

|          ..o..  |

+-----------------+                      #创建过程

 

key储存位置 #is_rsa.pub为公钥,id_rsa为私钥

wKiom1fP2Omg1j9MAAB04MzRNpA036.png

2)使用key加密目标主机的目标用户

ssh-copy-id  -i  /home/test/.ssh/id_rsa.pub username@IP

wKioL1fP2QSBT1SIAAFWHzwAxyk633.png

ssh-copy-id####上传key的工具

-i####指定使用的公钥

/home/test/.ssh/id_rsa.pub#####使用公钥的名称

root####被管理的目标用户

172.25.28.10####被管理用户所在主机的ip

wKiom1fP2RrT8kpgAAB-MtcmatE397.png-wh_50

高亮显示的authorized_keys文件即为最终创建的key文件。 #内容与公钥相同。可以发给特定用户以用于其登陆。

 

(3)sshd服务的简单配置

/etc/ssh/sshd_config###sshd服务的配置文件

48PermitRootLogin yes|no###是否允许root用户通过sshd的认证

78 PasswordAuthentication yes|no###开启或关闭用户密码认证

AllowUsers student westos###用户白名单,只允许在名单中出现的用户使用sshd服务

systemctl restart sshd###重新加载配置


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章