当前位置:   article > 正文

centos7 设置ssh_key 登陆 公钥与密钥,借助工具生成 .ppk 文件,_centos ppk 密钥

centos ppk 密钥

这里选择不对root进行直接操作,也就是会出现各个用户所对应的key

1.新增登陆用户,分配root权限组

  1. [root@localhost ~]# adduser zhw2
  2. [root@localhost ~]# passwd zhw2
  3. Changing password for user zhw2.
  4. New password:
  5. BAD PASSWORD: The password is shorter than 8 characters
  6. Retype new password:
  7. passwd: all authentication tokens updated successfully.

分配权限组

[root@localhost ~]# visudo
  1. root ALL=(ALL) ALL
  2. zhw ALL=(ALL) ALL #添加
  3. zhw2 ALL=(ALL) ALL #添加

2.修改ssh服务器配置文件

[root@localhost ~]# vim /etc/ssh/sshd_config

修改对应位置

  1. #允许root认证登录
  2. PermitRootLogin yes
  3. #允许密钥认证
  4. #RSAAuthentication (rsa认证)是只支持第1代ssh通讯协议使用的配置项,在CentOS7.4中被废除了,而且前面提到过CentOS7开始预设使用第二代通讯协议,在CentOS7.4中没有找到指定协议版本的配置行,
  5. RSAAuthentication yes
  6. #第2代ssh通讯协议的密钥验证选项是
  7. PubkeyAuthentication yes
  8. #默认公钥存放的位置
  9. AuthorizedKeysFile .ssh/authorized_keys
  10. PasswordAuthentication yes #可使用密码进行ssh登录

3.重启ssh服务器

service sshd restart

4.切换用户到zhw2

[zhw2@localhost ~]$ ssh-keygen -t rsa
回车到结束!

id_rsa.pub(公钥)

id_rsa(私钥)

  1. [zhw2@localhost ~]$ ssh-keygen -t rsa
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/home/zhw2/.ssh/id_rsa):
  4. Created directory '/home/zhw2/.ssh'.
  5. Enter passphrase (empty for no passphrase):
  6. Enter same passphrase again:
  7. Your identification has been saved in /home/zhw2/.ssh/id_rsa.
  8. Your public key has been saved in /home/zhw2/.ssh/id_rsa.pub.
  9. The key fingerprint is:
  10. SHA256:ejpL30daxTyQHAKqBZQ5omG+9krbXovtt75ZAR6Wikg zhw2@localhost.localdomain
  11. The key's randomart image is:
  12. +---[RSA 2048]----+
  13. | .oo .....o |
  14. |... +. .. .+ |
  15. |oE . .o= + |
  16. |o.. .o+ o = |
  17. | ..... .S. . . |
  18. | o . . o |
  19. |... .o .. + |
  20. |. o.+.o=o.. . |
  21. | oo+.+=B+ .. |
  22. +----[SHA256]-----+

切换到用户目录,将公钥文件重命名为authorized_keys

  1. [zhw2@localhost ~]$ cd /home/zhw2/.ssh/
  2. [zhw2@localhost .ssh]$ mv id_rsa.pub authorized_keys

将目录.ssh权限设置为700,公钥文件authorized_keys设置为644

  1. [zhw2@localhost .ssh]$ chmod 700 ../.ssh/
  2. [zhw2@localhost .ssh]$ chmod 644 authorized_keys

5.进行ssh测试(针对生成key的用户组)

  1. [zhw2@localhost ~]$ ssh 192.168.163.122
  2. The authenticity of host '192.168.163.122 (192.168.163.122)' can't be established.
  3. ECDSA key fingerprint is SHA256:jROccStnTU3ONKCFDDWC7hDJe/uFppaZ45LImsl8SNQ.
  4. ECDSA key fingerprint is MD5:f9:09:ad:29:66:06:1d:13:ab:7f:71:f9:25:6e:99:e0.
  5. Are you sure you want to continue connecting (yes/no)? yes
  6. Warning: Permanently added '192.168.163.122' (ECDSA) to the list of known hosts.
  7. Last login: Tue Mar 12 02:20:39 2019
  8. [zhw2@localhost ~]$

 

6.下载私钥,putty远程登陆。切换到root。下载私钥文件到本地(也可用winscp 直接下载)

 使用puttygen.exe,生成ppk文件

备注:如若想禁止root登陆,密码登录。。修改上面对应的参数。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/158104?site
推荐阅读
相关标签
  

闽ICP备14008679号