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. jQuery对标签、类样式、值、文档、DOM对象的操作

    jquery的标签属性操作 使用attr()方法对html标签属性进行操作,attr如果参数是一个参数,表示获取html标签的属性值,如果是两个参数则是设置标签属性名以及对象的属性值 .prop()适 ...

  2. 【leetcode】234. Palindrome Linked List

    234. Palindrome Linked List 1. 使用快慢指针找中点的原理是fast和slow两个指针,每次快指针走两步,慢指针走一步,等快指针走完时,慢指针的位置就是中点.如果是偶数个数 ...

  3. 卸载Mariadb-报错

    1. rpm -qa|grep aria MariaDB-client-10.1.22-1.x86_64MariaDB-devel-10.1.22-1.x86_64MariaDB-shared-10. ...

  4. C语言--第八周作业评分(5班)

    作业链接:https://edu.cnblogs.com/campus/hljkj/CS2017-5/homework/1400 一.评分要求 要求1 完成14.15周的所有PTA中题目集,总共4次题 ...

  5. PTA——类型转换

    PTA习题 7-6 厘米换算英尺英寸 (15 分) #include<stdio.h> int main(){ int a; int b,c; scanf("%d",& ...

  6. [Educational Codeforces Round 55 (Rated for Div. 2)][C. Multi-Subject Competition]

    https://codeforc.es/contest/1082/problem/C 题目大意:有m个类型,n个人,每个人有一个所属类型k和一个能力v,要求所选的类型的人个数相等并且使v总和最大(n, ...

  7. hdu2174 kiki's game 博弈

    Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes th ...

  8. day16 Hbase day17

    这个HBase学习了第二遍也不是太透彻PS:启动Hbase之前先启动Zookeeper.HDFS.yarn 1. hbase简介(是基于HDFS.相当于是一个缓存层) 1.1. 什么是hbase(列式 ...

  9. linqpad使用方法备忘

    1.使用EF更新数据库 void Main() { select item).ToList(); CM_BookPages.DeleteAllOnSubmit(items); SubmitChange ...

  10. 固态硬盘和机械硬盘双硬盘安装win10,提示无法找到系统

    选择兼容模式,自己慢慢找,不同的主板所在的位置不同,大概是cms(兼容的意思)这个选项,选择enable就可以了