Linux SSH实现无密码远程登录
一、 SSH无密码远程登录原理

二、 SSH实现无密码远程登录
实现主机A 无密码远程登录主机B
主机A IP地址:10.8.9.154
主机B IP地址:10.8.9.155
1、 主机A操作如下:
[root@cloucentos6 .ssh]# pwd #一般SSH生成公钥和私密会在.ssh目录下,如果没有此目录可以手动创建
/root/.ssh
[root@cloucentos6 .ssh]# ls #一般.ssh目录会存在一个文件known_hosts,此文件主要记录本地SSH远程登录过哪些主机
known_hosts
[root@cloucentos6 .ssh]# ssh-keygen -t rsa -P '' #执行ssh-keygen生成公钥和私钥,-P表示密码,’’ 表示空密码,也可以不使用 –P 参数,这样就要按三次回车,用 -P就输入一次回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #按一次回车键即可
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:
9c:f5:83:54:fd:da:6b:1a:9b:e3:d8:cf:ca:c9:b3:b4 root@cloucentos6.0
The key's randomart image is:
+--[ RSA 2048]----+
| .. |
| . . |
| o . |
| . + o .|
| S . o o |
| .. .|
| o .|
| *oBo |
| ..EOo |
+-----------------+
[root@cloucentos6 .ssh]# ls # id_rsa(私钥) id_rsa.pub (公钥)
id_rsa id_rsa.pub known_hosts
[root@cloucentos6 .ssh]# scp /root/.ssh/id_rsa.pub root@10.8.9.155:/root/.ssh/authorized_keys #把主机A /root/.ssh/id_rsa.pub 公钥复制到主机B /root/.ssh/authorized_keys文件里(要确认主机B已经创建好/root/.ssh目录),由于还没有免密码登录,所以要输入一次B主机的root密码
root@10.8.9.155's password: #输入主机B的密码
id_rsa.pub 100% 400 0.4KB/s 00:00
注意:主机B 目录/root/.ssh/authorized_keys文件需要具有读写权限,否则会提示远程失败
[root@ssticentos65 .ssh]# ls -l authorized_keys
-rw-r--r-- 1 root root 400 Jun 5 11:47 authorized_keys
现在主机A可以实现SSH无密码远程登录主机B (如果第一次登录需要输入 yes)
[root@cloucentos6 .ssh]# ssh root@10.8.9.155 'chmod 600 /root/.ssh/authorized_keys ; ls -l /root/.ssh/authorized_keys' #执行SSH远程主机B修改authorized_keys文件权限
-rw-------. 1 root root 400 1月 6 02:02 /root/.ssh/authorized_keys
特殊问题:
问题1:如果执行scp或ssh命令远程连接特殊慢才显示出输入密码提示还提示错误信息
[root@cloucentos6 .ssh]# scp /root/.ssh/id_rsa.pub root@10.8.9.155:/root/.ssh/authorized_keys #执行scp命令远程复制会出现连接缓慢并且还有警告
The authenticity of host '10.8.9.155 (10.8.9.155)' can't be established.
RSA key fingerprint is b6:a2:4d:65:af:cf:19:97:99:ff:1e:99:5f:ec:1b:7a.
Are you sure you want to continue connecting (yes/no)? yes #第一次登录,所以需要输入 yes
Warning: Permanently added '10.8.9.155' (RSA) to the list of known hosts.
解决办法:修改SSH配置文件/etc/ssh/ssh_config,手动添加GSSAPIAuthentication no
[root@cloucentos6 .ssh]#vim /etc/ssh/ssh_config
GSSAPIAuthentication no
[root@cloucentos6 .ssh]# scp /root/.ssh/id_rsa.pub root@10.8.9.155:/root/.ssh/authorized_keys
root@10.8.9.155's password:
问题2:/root目录下没有发现.ssh目录
linux-3ghc:~ # ls -a
. .bash_history .esd_auth .viminfo Downloads Templates dead.letter
.. .cache .gnupg .xsession-errors-:0 Music Videos inst-sys
.ICEauthority .config .local Desktop Pictures autoinst.xml
.Xauthority .dbus .rnd Documents Public bin
解决办法:因为系统没有使用ssh登录过,所以,ssh是没有记录到你的用户密码信息,只需要执行下列命令就可以生成.ssh目录
linux-3ghc:~ # ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is c2:ec:5d:98:45:b4:71:3c:c3:dd:5d:95:7d:20:dc:2f [MD5].
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Password:
Last login: Wed Feb 13 15:53:38 2019 from 10.8.9.11
linux-3ghc:~ # ls -a /root/
. .Xauthority .config .gnupg .ssh Desktop Music Templates bin
.. .bash_history .dbus .local .viminfo Documents Pictures Videos dead.letter
.ICEauthority .cache .esd_auth .rnd .xsession-errors-:0 Downloads Public autoinst.xml inst-sys
Linux SSH实现无密码远程登录的更多相关文章
- Linux系列之putty远程登录
在工作中,我们通常都是通过远程操作Linux服务器的,因此必须熟悉一些远程登录的软件,在此使用的是putty,在Windows上安装putty软件,通过该软件访问Linux主机. 1.远程登录步骤 1 ...
- Linux SSH安全策略限制IP登录方法(转)
本文介绍了Linux SSH安全策略限制IP登录的两种方法.具体如下: 方法一: 首先需要限制登录的ip(或者如果需要自己本地登录,查看最后登录ip即可) Vim /etc/hosts.allow 输 ...
- linux系统如何限制远程登录ip
在Linux系统上限制远程登录的IP,使用系统自带的配置文件. /etc/hosts.allow /etc/hosts.deny 匹配原则 先allow 后deny. 要求: 只允许 192.168 ...
- 在Linux系统上限制远程登录的IP
在Linux系统上限制远程登录的IP,使用系统自带的配置文件. /etc/hosts.allow /etc/hosts.deny 匹配原则 先allow 后deny.
- 华为S5700交换机初始化和配置SSH和TELNET远程登录方法
基础设置: 配置登陆IP地址<Quidway> system-view ...
- SSH免密码远程登录Linux
1. 有A,B两台机(Linux/unix), 要想从A用ssh远程登录到B上(假设各自的IP,A:192.168.100:B:192.168.1.104). 2. 在A机上,用“ssh-keygen ...
- linux ssh公钥免密码登录
ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 一.SSH公钥登录原理 在平时工作中我们经常要远程登录服务器,这就要用到SSH ...
- linux操作日志:远程登录设置
想要远程linux服务器,首先需要在服务器上开通ssh服务,安装命令如下: sudo apt-get install openssh-server 在上图的提示中,输入“y”,继续等待安装,安装成 ...
- 使用ssh命令进行远程登录
1.查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号.使用ssh -V命令可以得到版本号.需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用Op ...
随机推荐
- STL之std::set、std::map的lower_bound和upper_bound函数使用说明
由于在使用std::map时感觉lower_bound和upper_bound函数了解不多,这里整理并记录下相关用法及功能. STL的map.multimap.set.multiset都有三个比较特殊 ...
- pip升级Python程序包
列出当前安装的包: pip list 列出可升级的包: pip list --outdate 升级一个包: pip install --upgrade requests // mac,linux,un ...
- 7. 集成学习(Ensemble Learning)Stacking
1. 集成学习(Ensemble Learning)原理 2. 集成学习(Ensemble Learning)Bagging 3. 集成学习(Ensemble Learning)随机森林(Random ...
- Sahi (2) —— https/SSL配置(102 Tutorial)
Sahi (2) -- https/SSL配置(102 Tutorial) jvm版本: 1.8.0_65 sahi版本: Sahi Pro 6.1.0 参考来源: Sahi官网 Sahi Quick ...
- orderBy 传入属性的字符串
IEnumerable下面的的OrderBy可以用于集合的排序. public static IOrderedEnumerable<TSource> OrderBy<TSource, ...
- 用图片做div背景的列表布局 CSS代码
思路: 1.因为是竖型列表,所以外层用 相对定位,这样 在不会重叠在一起 relative 2.里面用绝对位置 absolute,覆盖在图片上面 3.这里有个小技巧,我里面有个特效,文字竖立,并向右旋 ...
- os.walk函数
import os# g = os.walk("D:\aaa") for i in os.walk(R"D:\aaa"): print(i)#执行结果如下('D ...
- MFC函数—— CFrameWnd::OnCreateClient
CFrameWnd::OnCreateClient virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext*pContext); ...
- JS设计模式学习实例之单例模式
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- CSS2.0中最常用的18条技巧
一.使用css缩写 使用缩写可以帮助减少你CSS文件的大小,更加容易阅读. 具体内容请浏览:CSS常用缩写语法 二.明确定义单位,除非值为0. 忘记定义尺寸的单位是CSS新手普遍的错误.在HTML中 ...