Linux(Centos)配置OpenSSH无密码登陆<转>
最近在搭建Hadoop环境需要设置无密码登陆,所谓无密码登陆其实是指通过证书认证的方式登陆,使用一种被称为"公私钥"认证的方式来进行ssh登录。 " 公私钥"认证方式简单的解释:首先在客户端上创建一对公私钥 (公钥文件:~/.ssh/id_rsa.pub; 私钥文件:~/.ssh/id_rsa)。然后把公钥放到服务器上(~/.ssh/authorized_keys), 自己保留好私钥.在使用ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配.如果匹配成功就可以登录了。 在Ubuntu和Cygwin 配置都很顺利,而在CentOS系统中配置时遇到了很多问题。故此文以Centos (Centos5 ) 为例详细讲解如何配置证书验证登陆,具体操作步骤如下: 1. 确认系统已经安装好OpenSSH的server 和client
安装步骤这里不再讲述,不是本文的重点。 2. 确认本机sshd的配置文件(需要root权限)
$ vi /etc/ssh/sshd_config
找到以下内容,并去掉注释符”#“ RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys 3. 如果修改了配置文件需要重启sshd服务 (需要root权限)
$ vi /sbin/service sshd restart 4. ssh登陆系统 后执行测试命令:
$ ssh localhost 回车会提示你输入密码,因为此时我们还没有生成证书 5.生成证书公私钥的步骤:
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 6.测试登陆 ssh localhost:
$ ssh localhost 正常情况下会登陆成功,显示一些成功登陆信息,如果失败请看下面的 一般调试步骤
7.一般调试步骤
本人在配置时就失败了,按照以上步骤依旧提示要输入密码。于是用ssh -v 显示详细的登陆信息查找原因: $ ssh -v localhost 回车显示了详细的登陆信息如下: 。。。。。。省略 debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information Unknown code krb5 195
debug1: Next authentication method: publickey debug1: Trying private key: /home/huaxia/.ssh/identity debug1: Trying private key: /home/huaxia/.ssh/id_rsa debug1: Offering public key: /home/huaxia/.ssh/id_dsa debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug1: Next authentication method: password huaxia@localhost's password:
同时用root用户登陆查看系统的日志文件: $tail /var/log/secure -n 20 。。。。。。省略 Jul 13 11:21:05 shnap sshd[3955]: Accepted password for huaxia from 192.168.8.253 port 51837 ssh2 Jul 13 11:21:05 shnap sshd[3955]: pam_unix(sshd:session): session opened for user huaxia by (uid=0) Jul 13 11:21:47 shnap sshd[4024]: Connection closed by 127.0.0.1 Jul 13 11:25:28 shnap sshd[4150]: Authentication refused: bad ownership or modes for file /home/huaxia/.ssh/authorized_keys Jul 13 11:25:28 shnap sshd[4150]: Authentication refused: bad ownership or modes for file /home/huaxia/.ssh/authorized_keys Jul 13 11:26:30 shnap sshd[4151]: Connection closed by 127.0.0.1 。。。。。。省略
从上面的日志信息中可知文件/home/huaxia/.ssh/authorized_keys 的权限有问题。 查看/home/huaxia/.ssh/ 下文件的详细信息如下: $ ls -lh ~/.ssh/ 总计 16K -rw-rw-r-- 1 huaxia huaxia 602 07-13 11:22 authorized_keys -rw------- 1 huaxia huaxia 672 07-13 11:22 id_dsa -rw-r--r-- 1 huaxia huaxia 602 07-13 11:22 id_dsa.pub -rw-r--r-- 1 huaxia huaxia 391 07-13 11:21 known_hosts 修改文件authorized_keys的权限(权限的设置非常重要,因为不安全的设置安全设置,会让你不能使用RSA功能 ): $ chmod 600 ~/.ssh/authorized_keys
再次测试登陆如下: $ ssh localhost Last login: Wed Jul 13 14:04:06 2011 from 192.168.8.253 看到这样的信息表示已经成功实现了本机的无密码登陆。 8.认证登陆远程服务器(远程服务器OpenSSH的服务当然要启动)
拷贝本地生产的key到远程服务器端(两种方法) 方法一: $cat ~/.ssh/id_rsa.pub | ssh 远程用户名@远程服务器ip 'cat - >> ~/.ssh/authorized_keys' 方法二: 在本机上执行: $ scp ~/.ssh/id_dsa.pub michael@192.168.8.148:/home/michael/ 登陆远程服务器michael@192.168.8.148 后执行: $ cat id_dsa.pub >> ~/.ssh/authorized_keys 本机远程登陆192.168.8.148的测试: $ssh michael@192.168.8.148 Linux michael-VirtualBox 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux Ubuntu 10.10
Welcome to Ubuntu! * Documentation: https://help.ubuntu.com/
216 packages can be updated. 71 updates are security updates.
New release 'natty' available. Run 'do-release-upgrade' to upgrade to it.
Last login: Wed Jul 13 14:46:37 2011 from michael-virtualbox michael@michael-VirtualBox:~$
可见已经成功登陆。 如果登陆测试不成功,需要修改远程服务器192.168.8.148上的文件authorized_keys的权限(权限的设置非常重要,因为不安全的设置安全设置,会让你不能使用RSA功能 ) chmod 600 ~/.ssh/authorized_keys 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-02/54595.htm
Linux(Centos)配置OpenSSH无密码登陆<转>的更多相关文章
- Linux CentOS 配置Tomcat环境
一.下载Tomcat 下载Tomcat方式也有两种,可以参考我的前一篇博文Linux CentOS配置JDK环境,这边就不再赘述. 二.在Linux处理Tomcat包 1.创建tomcat文件夹 mk ...
- CentOS配置ssh无密码登录
CentOS配置ssh无密码登录的注意点 前提配置:使用root登录修改配置文件:/etc/ssh/sshd_config,将其中三行的注释去掉,如下: 然后重启ssh服务:service s ...
- 安装SSH,配置SSH无密码登陆
环境:ubuntu16.04 Ubuntu 默认已安装了 SSH client,所以我们还需要安装 SSH server: sudo apt-get install openssh-server 安装 ...
- 配置ssh无密码登陆Linux
Windows下面的话需要安装git,或者其他能执行shell命令的软件 1.首先要先修改SSH的配置文件 vi /etc/ssh/sshd_config#修改配置文件 #如果被#注释了,就取消#号, ...
- 【Linux】Centos配置ssh无密码登录
[测试环境] 刚好重新做mgr就搞下吧,主要论文好长~想多做几遍再看~ master1 192.168.13.111 master2 192.168.13.112 master3 192.168. ...
- linux centos 配置 svn 服务器
首先介绍一下吧,Subversion(SVN) 是一个开源的版本控制系統, 也就是说 Subversion 管理着随时间改变的数据. 这些数据放置在一个中央资料档案库 (repository) 中. ...
- SQL记录-Linux CentOS配置ORACLE 12c
1.准备LIINX软件包 操作系统:centos7 虚拟机:VMware 12 JDK:1.8 数据库:oracle 12c 2.配置基础环境 2.1 部署虚拟机VM(过程略) 2.2 部署操作系统C ...
- Linux CentOS 配置Yaf框架
简介 Yaf框架想必大家都有所了解,它是一个开源的高性能的PHP框架 官网地址:https://www.php.net/manual/zh/book.yaf.php Yaf开发文档:https://w ...
- Linux CentOS 配置JDK环境
一.下载JDK 下载JDK的方式有两种: 1.Linux中使用wget下载 1.使用命令安装wget yum install wget 2.下载 wget 'http://download.oracl ...
随机推荐
- Android通过代码获取View
View view = LayoutInflater.from(mContext).inflate(R.layout.song_item_adapter, null); LayoutInflater ...
- Independence独立
Independence refers to the degree to which each test case stands alone. That is, does the success or ...
- 序列for循环语句
序列for循环语句 序列for循环语句允许重复遍历一组序列,而这组序列可以是任何可以重复遍历的序列,如由begin()和end()函数定义的STL序列.所有的标准容器都可用作这种序列,同时它也同样可以 ...
- bzoj1036 树的统计Count
第一次写链剖,于是挑了个简单的裸题写. 以下几点要注意: 1.链剖中的height是从根到该店经过的轻边个数 2.分清num与sum..... #include<cstdio> #incl ...
- static用法总结
C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. 一.面向过程设计中的st ...
- C++中的基类与派生类
派生类的继承方式总结: 继承方式 说明 public 基类的public和protected的成员被派生类继承后,保持原来的状态 private 基类的public和protected的成员被派生类继 ...
- 基于MapReduce的关系代数运算(1)
1.选择运算 Map函数:对R中的每个元组t,检测它是否满足条件C,如果满足,则产生一个键值对(t,t) Reduce函数:直接将每个键值对传递到输出即可 2.投影运算 Map函数:对R中的每个元组t ...
- 北信源VRVEIS网管软件测试
650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...
- 第一百九十二天 how can I 坚持
早上去中关村森林公园跑了会步,下午看了部电影<夏洛特烦恼>,感觉电影跟我看的那部小说差不多,还是挺不错的. 睡觉.
- 理解Python元类(转)
add by zhj:先收藏了,有时间看,图倒是不少,可以配合stackover flow上那篇文章一起看 原文:http://blog.ionelmc.ro/2015/02/09/understan ...