vim /etc/ssh/sshd_config, 下面三行去掉注释符号#
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys mkdir -p ~/.ssh
chmod ~/.ssh

生成公钥和私钥

[root@localhost .ssh]# cd ~/.ssh
[root@localhost .ssh]# 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:
::::df:8e:6e:0f:ce:ee:a7:fd:f9:6e:: root@localhost.localdomain
The key's randomart image is:
+--[ RSA ]----+
| .. |
| . . |
| ... |
| .... E |
| o oo. S . |
| +. .. . . |
| .. . . |
| ooo. ... |
| +*+o.o=o |
+-----------------+
[root@localhost .ssh]#

配置

[root@localhost .ssh]# cat id_rsa.pub > authorized_keys
[root@localhost .ssh]# chmod authorized_keys
[root@localhost .ssh]# ll
total
-rw-------. root root Jul : authorized_keys
-rw-------. root root Jul : id_rsa
-rw-r--r--. root root Jul : id_rsa.pub

下载id_rsa到本地,用pyTTYgen转换为.ppk文件,配置到putty中,配置登陆用户名root

login as: root
Server refused our key
root@192.168.88.133's password:

登陆失败。。。需要disable selinux

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]#

再次尝试成功!

Using username "root".
Authenticating with public key "imported-openssh-key"
Last login: Mon Jul :: from 192.168.88.1
[root@localhost ~]#

永久disable selinux
/etc/selinux/config,修改SELINUX=disabled 或者permissive

问题原因:

生成的~/.ssh/authorized_keys 文件没有selinux上下文属性,导致无法通过Selinux认证,查看该文件属性如下:ll -Z filename

[root@postfixmx mnt]# restorecon -r -v /root  其它用户为/home

restorecon reset /root/.config context system_u:object_r:gconf_home_t:s0->system _u:object_r:config_home_t:s0
restorecon reset /root/.config/ibus context system_u:object_r:gconf_home_t:s0->s ystem_u:object_r:config_home_t:s0
restorecon reset /root/.config/ibus/bus context system_u:object_r:gconf_home_t:s 0->system_u:object_r:config_home_t:s0
restorecon reset /root/.ssh context unconfined_u:object_r:admin_home_t:s0->uncon fined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/authorized_keys context unconfined_u:object_r:admin_ home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/id_rsa context unconfined_u:object_r:admin_home_t:s0 ->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/id_rsa.pub context unconfined_u:object_r:admin_home_ t:s0->unconfined_u:object_r:ssh_home_t:s0
[root@postfixmx mnt]#

该命令的作用了恢复/home 目录下所有文件的默认selinux安全上下文属性。

------------------------

如果需要配置linux服务器之间的ssh无密码互访,可以使用上述的ssh key认证实现

对要登录的服务器上的/etc/ssh/sshd_config文件做如下修改,记得重启sshd服务啊!

RSAAuthentication yes         #允许rsa key 认证
PubkeyAuthentication yes    #允许rsa key 认证
PermitEmptyPasswords no #不允许空密码
PasswordAuthentication no #不允许密码认证,这个根据实际情况而定,一般有rsa key认证登陆的话,就没必要密码认证了

from的服务器上的.ssh目录中放置id_rsa即可。

centos 配置puTTY rsa自动登录的更多相关文章

  1. putty实现自动登录的方法(ssh和ssh2)

    介绍putty实现自动登录的方法.   1.登录主机并输入ssh-keygen -t rsa  提示Enter file in which to save the key (/root/.ssh/id ...

  2. 转载:PuTTY的自动登录设置

    转自:http://blog.segmentfault.com/zair/1190000000639516 PuTTY是Windows下非常好用的SSH远程登陆客户端.本文介绍两种自动登录的设置方法. ...

  3. CentOS配置SSH免密码登录后,仍提示输入密码

    CentOS配置SSH无密码登录需要3步: 生成公钥和私钥 导入公钥到认证文件,更改权限 测试 1.生成公钥和私钥 ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 默 ...

  4. 解决:centos配置ssh免密码登录后仍要输入密码

    转自https://www.jb51.net/article/121180.htm 第一步:在本机中创建秘钥 1.执行命令:ssh-keygen -t rsa 2.之后一路回车就行啦:会在-(home ...

  5. CentOS配置SSH免密登录

    假如我们有两台CentOS机器,192.168.199.101,192.168.199.102,要想在101上远程连接102可以通过ssh命令来实现 ssh 192.168.199.102 如果没有配 ...

  6. centos配置ssh免密码登录

    master.slave1两台机器实现ssh免密码登录,user:hadoop,passwd:123456 1.设置master: vi /etc/sysconfig/network hostname ...

  7. centos配置ssh免密码登录后,仍提示输入密码

    配置SSH无密码登录需要3步: 1.生成公钥和私钥 2.导入公钥到认证文件,更改权限 3.测试 1.生成公钥和私钥 ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 默 ...

  8. [整理]配置SSH密钥自动登录远程服务器

    原理: 公钥私钥匹配通过验证,允许访问服务器. 简单步骤: 1.在本地创建一对密钥 2.将公钥传到需要访问的服务器上 3.将公钥放入服务器的authorized_keys,确保访问时能通过验证 4.本 ...

  9. CentOS 配置MySQL允许远程登录

    Mysql为了安全性,在默认情况下用户只允许在本地登录,可是在有此情况下,还是需要使用用户进行远程连接,因此为了使其可以远程需要进行如下操作: 一.允许root用户在任何地方进行远程登录,并具有所有库 ...

随机推荐

  1. NOI-1.1-04输出保留3位小数的浮点数

    04:输出保留3位小数的浮点数 总时间限制:  1000ms 内存限制:  65536kB 描述 读入一个单精度浮点数,保留3位小数输出这个浮点数. 输入 只有一行,一个单精度浮点数. 输出 也只有一 ...

  2. 获取Linux服务器基本信息的shell脚本

    测试运行环境: SLES12SP2 #!/bin/bash #系统名称:os_type=$(uname -o | awk '{print " | "$0}') #系统位数:32/6 ...

  3. 更换JDK版本时的问题:Error: could not open `C:\Java\jre7\lib\amd64\jvm.cfg'

    1.先把oracle自带的weblogic给卸载了,然后打开eclipse,发现报错了:Error: could not open `C:\Java\jre7\lib\amd64\jvm.cfg' J ...

  4. 网络IP和网络掩码以及网关的学习

    192.168.10.1/24,192.168.1.1/30是什么意思啊? 表示地址范围你把这些前面的值转换成2进制 就是变成一个32位的地址比如192.168.10.1就变成11000000.101 ...

  5. 《DSP using MATLAB》Problem 5.14

    说明:这两个小题的数学证明过程都不会,欢迎博友赐教. 直接上代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  6. hdu4300 Clairewd’s message 扩展KMP

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  7. 【java编程】加载Resources配置文件的方法

    一.加载配置实现k-v //FILTER_PROPERTY_NAME=META-INF/abc.properties private void loadFilterConfig(Properties ...

  8. MySQL--查看内存信息

    常见查看内存信息命令 ## 使用free -m命令查看 free -m ## 使用cat /proc/meminfo 查看 cat /proc/meminfo ## 使用dmidecode命令查看 d ...

  9. Makefile introduction (very old presentation)

  10. Office 2010 打开文件后所有的格式成了时间的解决方法

    最新不知道什么原因,每一个 Excel 文件打开后,时需的数据都成了时间格式. 而且改都改不了,改了后第二次打开又成了这个样子. 最后找到解决方法. 如下动画,将 [$F400] 数据格式删除就可以. ...