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. Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at xxxx/usr/bin/automake line 3939.

    /********************************************************************** * Unescaped left brace in re ...

  2. Python中random模块在主函数中设置随机种子是否对于调用的函数中的随机值产生影响?

    一个问题,加入我有一个工程文件,在main函数里面调用random模块,设置随机种子,主函数中的随机种子的设置是否会影响主函数所调用的函数中的随机值? 实际上这个问题非常重要,比如你在跑网络的时候,初 ...

  3. ldd 查看程序依赖库

    ldd 查看程序依赖库 https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/ldd.html

  4. Windows 10瘦身

    Windows操作系统功能越来越强大,同时体型也越来越臃肿.安装盘没有60Gb都不敢安装.Windows10 安装最低磁盘要求20G ====瘦身基础篇,适合任何用户:(可见目录,简单迁移)1. 安装 ...

  5. 【BZOJ3240】【UOJ#124】【NOI2013】矩阵游戏

    终于看懂一道题QAQ然而NOI都是这种难度题怎么玩QAQ 原题: 婷婷是个喜欢矩阵的小朋友,有一天她想用电脑生成一个巨大的n行m列的矩阵(你不用担心她如何存储).她生成的这个矩阵满足一个神奇的性质:若 ...

  6. static关键字的使用(有个深刻领悟)

    没有实例化对象的时候进行可以调用static 属性  static方法 (用类名去调用) 非static定义的方法可以调用static的属性或方法. static定义的方法不能调用非static的方法 ...

  7. linux令普通用户拥有root权限

    如题,平时我们在自己电脑上玩linux,基本都是一个root用户就够了(反正我99%时间都是直接用root用户登录系统),可如果在公司里就不行了,有时候需要多个用户对系统具有root权限,类似与一个系 ...

  8. Match 3 小项目学习

    using UnityEngine; using System.Collections; using Holoville.HOTween; /// <summary> /// 游戏逻辑 / ...

  9. 一般化数值算法(accumluate,inner_product,partial_sum,adjacent_difference)

    accumulate template<class InputIterator, class T> T accumulate( InputIterator _First, InputIte ...

  10. python之路---06 小数据池 编码

    二十二.小数据池, id()    进行缓存 1.小数据池针对的是: int, str, bool 2.在py文件中几乎所有的字符串都会缓存.   在cmd命令窗口中几乎都不会缓存   不同的解释器有 ...