前阵子搭建Hadoop时,配置了本机(localhost)的ssh的公钥到authorized_keys文件中,但是在ssh连接localhost时仍然提示需要输入密码,后来发现是$HOME/.ssh/authorized_keys这个文件的权限问题引起的。其原因是,不能让所有者之外的用户对authorized_keys文件有写权限,否则,sshd将不允许使用该文件,因为它可能会被其他用户篡改。
命令行的演示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[hadoop@guest1 ~]$ cd .ssh/[hadoop@guest1 .ssh]$ ll
total 16-rw-rw-r--1 hadoop hadoop  395 Jan 1218:37 authorized_keys
-rw-------1 hadoop hadoop 1675 Jan 1218:36 id_rsa
-rw-r--r--1 hadoop hadoop  395 Jan 1218:36 id_rsa.pub
-rw-r--r--1 hadoop hadoop  796 Jan  6 08:40 known_hosts
#注意这里的authorized_keys文件的权限;这时该文件中的key是不起作用的。#用chmod修改authorized_keys文件的权限[hadoop@guest1 .ssh]$ chmod g-w authorized_keys
[hadoop@guest1 .ssh]$ ll
total 16-rw-r--r--1 hadoop hadoop  395 Jan 1218:37 authorized_keys
-rw-------1 hadoop hadoop 1675 Jan 1218:36 id_rsa
-rw-r--r--1 hadoop hadoop  395 Jan 1218:36 id_rsa.pub
-rw-r--r--1 hadoop hadoop  796 Jan  6 08:40 known_hosts
                
#修改后,sshd就可以正常使用authorized_keys文件了[hadoop@guest1 ~]$ ssh localhost
Last login: Sat Jan 1218:40:332013 from localhost
[hadoop@guest1 ~]$ exitlogout
Connection to localhost closed.
[hadoop@guest1 ~]$

后来,我详细查了一下,如果authorized_keys文件、$HOME/.ssh目录 或 $HOME目录让本用户之外的用户有写权限,那么sshd都会拒绝使用 ~/.ssh/authorized_keys 文件中的key来进行认证的。
“man sshd”命令查看对authorized_keys文件的描述如下:

1
2
3
4
5
6
7
8
9
10
11
man sshd
.....
     ~/.ssh/authorized_keys
             Lists the public keys (DSA/ECDSA/RSA) that can be used for logging in as this user.  The format of
             this file is described above.  The content of the file is not highly sensitive, but the recommended
             permissions are read/write for the user, and not accessible by others.
     
             If this file, the ~/.ssh directory, or the user's home directory are writable by other users, then the
             file could be modified or replaced by unauthorized users.  In this case, sshd will not allow it to be
             used unless the StrictModes option has been set to “no”.
........
 
 

ssh配置authorized_keys后仍然需要输入密码的问题的更多相关文章

  1. Hadoop集群搭建(cluster setup),ssh免密后一直要求输入密码的原因

    前段时间,网上有言SHA-1加密技术,已经被谷歌公司破解,在linux系统中,集群间加密的技术是用DSA秘钥,秘钥本身其实是一种算法,就像前面说的SHA-1也是加密算法的一种. 免密在linux系统中 ...

  2. ssh复制公钥成功后仍需输入密码

    1,网上说权限问题 登录流程: 被登录机器的文件权限: //用户权限 chmod 700 /home/username //.ssh文件夹权限 chmod 700 ~/.ssh/ // ~/.ssh/ ...

  3. ssh-keygen的使用方法及配置authorized_keys两台linux机器相互认证

    一.概述 1.就是为了让两个linux机器之间使用ssh不需要用户名和密码.采用了数字签名RSA或者DSA来完成这个操作 2.模型分析 假设 A (192.168.20.59)为客户机器,B(192. ...

  4. SSH配置免秘钥登录

    一.  SSH 配置免秘要登录 配置SSH 免秘要登录,虽然就那么几步,但总是会出现点小问题,今天就做下记录.SSH 免秘钥就是让两台机器相互信任,不需要输入密码就能相互登录.配置相互信任就是把各自的 ...

  5. ssh配置含义解释

    ssh包括客户端配置(ssh_config)和服务端配置(sshd_config) 一.客户端配置ssh_config,客户端软件有SecureCRT.putty.Xshell等 “#”表示注释,虽然 ...

  6. jenkins自动化部署项目5 -- 系统管理-系统设置ssh配置

    [系统管理]-[系统设置] 如果应用服务(前端后台)要部署在linux服务器上,我选择的是用ssh 为了jenkins登录远程登录linux服务器可以免密登录,先配置公钥和私钥: 我是在windows ...

  7. CentOS SSH配置

    默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此.所以这里就不介绍OpenSSH的安装了. SSH配置: 1.修改vi /etc/ssh/sshd_config,根据模板将要修改的 ...

  8. github SSH配置

    目录 github SSH配置 前言 ssh 配置 github SSH配置 前言 github有两种更新的渠道,一种是https的,一种是ssh的,其中https每次都要输入密码,非常烦.所以,最好 ...

  9. mysql+ssh 配置(转载)

    Mysql+ssh配置 一.Linux平台间mysql+ssh配置 本机地址为:192.168.189.133 mysql服务器地址为:192.168.189.139 linux命令行下使用ssh命令 ...

随机推荐

  1. (C++)浅谈多态基类析构函数声明为虚函数

    主要内容: 1.C++类继承中的构造函数和析构函数 2.C++多态性中的静态绑定和动态绑定 3.C++多态性中析构函数声明为虚函数 1.C++类继承中的构造函数和析构函数 在C++的类继承中, 建立对 ...

  2. Toast.makeText 方法出错 java.lang.RuntimeException

    接手以前同事留下的代码,今天突然出现了一个bug: java.lang.RuntimeException: Can't create handler inside thread that has no ...

  3. Dreamweaver如何设置自动换行,修改字体

    1 打开和关闭自动换行功能 查看-代码视图选项 2 调整字体大小和类别

  4. Laravel 隐藏域如何实现?

    Laravel 隐藏域如何实现?   在 Blade 模板中,我们可以使用 method_field 方法来创建隐藏域.   {{ method_field('DELETE') }} 其转化为 HTM ...

  5. Android调用OCR识别图像中的文字

    // CharacterExtractor.java // Copyright (c) 2010 William Whitney // All rights reserved. // This sof ...

  6. Vertica7 Native Connection Load Balance

    原文链接:Vertica7 Native Connection Load Balance 在Vertica7曾经的版本号中,Vertica是通过Linux的Virtual IP来实现连接的负载均衡的, ...

  7. 一些Java面试题深入分析

    一.&和&&的差别? &和&&都能够用作逻辑与的运算符.表示逻辑与(and),当运算符两边的表达式的结果都为true时.整个运算结果才为true,否则, ...

  8. Android开发之定位系统

    2013-07-04 定位系统 全球定位系统(Global Positioning System, GPS), 又称全球卫星定位系统. 最少只需其中3颗卫星,就能迅速确定用户组地球所处的位置及海拔高度 ...

  9. Android中 单位 介绍

    看到有很多网友不太理解dp.sp和px的区别:现在这里介绍一下dp和sp.dp也就是dip.这个和sp基本类似.如果设置表示长度.高度等属性时可以使用dp 或sp.但如果设置字体,需要使用sp.dp是 ...

  10. 文件流(fstream, ifstream, ofstream)的打开关闭、流状态

    一.文件流 ofstream,由ostream派生而来,用于写文件 ifstream,由istream派生而来, 用于读文件 fstream,由iostream派生而来,用于读写文件 二.打开文件 说 ...