软件SecureCRT的下载链接:https://pan.baidu.com/s/1-l9bwy4o3gRBUsugw9Jz1w
Linux服务器的IP:192.168.168.130/24
在Windows客户端创建密钥对:( 工具》创建公钥 )
创建通行短语:(可选的,留空就是不需要通行短语)
选择密钥对长度:( 默认就是 1024 )
自定义密钥对文件的保存位置:
笺注:为了兼容多个不同的密钥对,最好不要设为全局公钥
生成的密钥对文件:
私钥文件的内容:(每次生成的内容都不一样的)
公钥文件的内容:(每次生成的内容都不一样的)
#######
以下是设置使用用户root进行密钥对验证:
yum -y install openssh-clients
ssh 127.0.0.1
会给用户root生成一个文件夹:
[root@localhost ~]# ls -alh
总用量 72K
dr-xr-x---. 5 root root 4.0K 9月 7 12:34 .
dr-xr-xr-x. 22 root root 4.0K 9月 7 12:28 ..
-rw-------. 1 root root 1.1K 7月 5 2018 anaconda-ks.cfg
-rw-------. 1 root root 1.9K 6月 23 03:27 .bash_history
-rw-r--r--. 1 root root 18 5月 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 5月 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 9月 23 2004 .bashrc
drwxr-xr-x. 2 root root 4.0K 6月 23 02:23 .composer
-rw-r--r--. 1 root root 100 9月 23 2004 .cshrc
-rw-r--r--. 1 root root 14K 7月 5 2018 install.log
-rw-r--r--. 1 root root 3.5K 7月 5 2018 install.log.syslog
-rw-r--r--. 1 root root 187 6月 23 02:22 .pearrc
drwxr-----. 3 root root 4.0K 6月 23 02:22 .pki
drwx------ 2 root root 4.0K 6月 23 02:59 .ssh
-rw-r--r--. 1 root root 129 12月 4 2004 .tcshrc
把公钥文件的内容全部复制到服务器对应用户root的 ~/.ssh/authorized_key 文件中:( ~/.ssh/authorized_keys 默认是不存在的)
[root@localhost ~]# vi ~/.ssh/authorized_keys
追加:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDig7LMG3m08fX/todhqAJS8qEKpxAhMz4WSxcQWtnH1M1nTZjh6LHN65oAl5yhAdnIlsGZq5C9DbwVLBH2sCADeR9fctPiZw+LyESBvZjUPiniyAErtPZD3Y/plFoLEBQOCROPUYT1/HednF8VQbpwmUcDhu1PhsOvUaLaDiyujw== jacky@jacky-PC
效果:
[root@localhost ~]# cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDig7LMG3m08fX/todhqAJS8qEKpxAhMz4WSxcQWtnH1M1nTZjh6LHN65oAl5yhAdnIlsGZq5C9DbwVLBH2sCADeR9fctPiZw+LyESBvZjUPiniyAErtPZD3Y/plFoLEBQOCROPUYT1/HednF8VQbpwmUcDhu1PhsOvUaLaDiyujw== jacky@jacky-PC
##注意公钥文件的权限:同组或者其他用户对该文件不能有写入权限,否则会无法成功使用密钥对验证!!! (权限要为644)
[root@localhost ~]# chmod 644 ~/.ssh/authorized_keys
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# pwd
/root/.ssh
[root@localhost .ssh]# ll
总用量 8
-rw-r--r-- 1 root root 228 6月 23 02:59 authorized_keys
-rw-r--r-- 1 root root 391 6月 23 02:55 known_hosts
登录验证方式:(也可以进入文件里修改,命令本身是有的)
// 禁止空密码用户远程登录
echo 'PermitEmptyPasswords no' >> /etc/ssh/sshd_config
// 启用密钥对验证
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
// 指定公钥库数据文件
echo 'AuthorizedKeysFile .ssh/authorized_keys' >> /etc/ssh/sshd_config
// 禁止密码验证(可选)
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
重启sshd服务:
[root@localhost ~]# service sshd restart
停止 sshd:[确定]
正在启动 sshd:[确定]
######
SecureCRT选择密钥对认证登录:
注释:要把“公钥”调到最上面。
为了兼容多个不同的密钥对,最好使用会话公钥设置
输入通行短语:(不需要输入用户、密码)
注释:假如前面没有创建通行短语,就没有这个步骤了。
密钥对验证登录成功:
笺注:
修改了用户root的密码,也不会影响使用密钥对登录系统的;
也可以给其他用户配置密钥对验证的,其过程与上面的如出一辙;
假如,开启了密钥对验证,且关闭了密码验证,那只能通过密钥对进行SSH登录了,但不会影响在操作台的登录;
在“会话选项”可以自定义调节公钥的:
相关文章:
Filezilla和WinSCP使用密钥对验证
Xshell4+密钥对验证
Linux之间的密钥对验证(一)
SecureCRT远程管理Linux(一)
Oracle Linux6.9的安装
PuTTY远程管理CentOS8
PuTTY远程管理Oracle Linux6.9
#################################
#################################
亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^
【刁嘴娃-卤汁牛肉80g】 麻辣五香味零食风干手撕牛肉干 【非偏远地区满79包邮】
干衣机家用双层衣柜宝宝专用烘干机超静音 烘衣器省电杀菌烘衣机
【送两个吹风嘴】飞科大功率电吹风发廊机冷热风负离子吹风筒家用静音吹风机
|