• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

通过SSH进行密钥认证自动登录Linux服务器

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

传统的网络服务程序,SSH的英文全称是 Secure Shell,通过使用ssh,可以对所有的传输的数据进行加密,这样既可以防止攻击又可以防止IP欺骗。

SSH 提供2种级别的安全验证

1,基于口令的安全验证,这也是我们常用的一种,只要知道用户名和密码,就可以远程登陆到远程主机上。

2,基于密钥的安全认证,就是说用户必须为自己创建一对密钥,并把公用密钥放到需要访问的服务器上。

2种安全级别的验证,后者相对比前者更安全一些,第二种级别不需要在网络上传递口令。

SSH密钥认证登录配置

原理:用户首先需要为自己创建一对密钥:公钥(用在登录的服务器上)和私钥。OPENSSH 公开的密钥的密码体质有RSA,DSA等,这里就用RSA。

客户端ip:192.168.72.11

服务器ip:192.168.72.129

密钥认证的生成


复制代码
代码如下:
[root@xyly ~]# ifconfig eth0 | awk ‘/inet addr/{print }’
inet addr:192.168.72.11 Bcast:192.168.72.255 Mask:255.255.255.0</p> <p>[root@xyly ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #密钥报存的位置和名称
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:
04:c5:7a:57:f6:2e:9c:1f:b5:e7:45:b3:11:f3:c7:18 root@xyly

公钥已经生成

现在把公钥上传到另一台服务器上去。


复制代码
代码如下:
[root@xyly ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
The authenticity of host ’192.168.72.129 (192.168.72.129)’ can’t be established.
RSA key fingerp
rint is 3b:26:19:2e:51:ca:cc:de:ac:bc:00:09:f0:7c:7d:f1.
Are you sure you want to continue connecting (yes/no)? yes #由于是第一次登录,服务器要进行确认
Warning: Permanently added ’192.168.72.129′ (RSA) to the list of known hosts.
Address 192.168.72.129 maps to localhost, but this does not map back to the address – POSSIBLE BREAK-IN ATTEMPT!
[email protected]′s password:
Now try logging into the machine, with “ssh ‘[email protected]′“, and check in:</p> <p>.ssh/authorized_keys #把公钥上传的位置和公钥的文件名</p> <p>to make sure we haven’t added extra keys that you weren’t expecting.

登录到服务器上,查看公钥是否上传


复制代码
代码如下:
[root@localhost ~]# ll .ssh/authorized_keys
-rw——- 1 root root 391 Aug 4 18:31 .ssh/authorized_keys

说明公钥上传成功了。

修改ssh配置文件,设置公钥认证登录

将下边2行的注释去掉,重启ssh服务


复制代码
代码如下:
RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys</p> <p>/etc/init.d/sshd restart

配置完毕,现在开始登录一下


复制代码
代码如下:
[root@xyly ~]# ssh 192.168.72.129
Address 192.168.72.129 maps to localhost, but this does not map back to the address – POSSIBLE BREAK-IN ATTEMPT!
Last login: Thu Aug 4 18:08:05 2011 from 192.168.72.1
[root@localhost ~]#

现在不用输入密码,就可以登录了。退出登录


复制代码
代码如下:
[root@localhost ~]# exit
logout
Connection to 192.168.72.129 closed.

linux ssh 密钥认证无需输入密码即可登录,在设置密钥的同时,也可以输入密码,即可密码+密钥认证就可以完成!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
禁用远程主机对SSH的公钥进行检查的方法发布时间:2022-02-10
下一篇:
初探Linux的系统日志发布时间:2022-02-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap