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 ...
随机推荐
- Improving Performance【转】
This section provides solutions to some performance problems, and describes configuration best pract ...
- 【Socket】linux下http服务器开发
1.mystery引入 1)超文本传输协议(HTTP)是一种应用于分布式.合作式.多媒体信息系统的应用层协议 2)工作原理 1)客户端一台客户机与服务器建立连接后,会发送一个请求给服务器,请求方式的格 ...
- MediaType是application/x-www-form-urlencoded的接口测试方法
先看接口: @POST @Path("/deleteById") //@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaTy ...
- 使用ViewPager和Fragment实现滑动导航
ViewPage是android-support-v4.jar包提供的用于页面滑动的库,android-support-v4.jar是google推荐使用的一个类库,在项目中使用之前,你必须其添加到项 ...
- Path-to-PegExp的使用
下载: npm install path-to-regexp --save 引入: var pathToRegexp = require('path-to-regexp') 或者 import pat ...
- css样式实现左边的固定宽度和高度的图片或者div跟随右边高度不固定的文字或者div垂直居中(文字高度超过图片,图片跟随文字居中,反之文字跟随图片居中非table实现)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【MLP】多层感知机网络
BPN(Back Propagation Net) 反向传播神经网络是对非线性可微分函数进行权值训练的多层网络,是前向神经网络的一种. BP网络主要用于: 1)函数逼近与预测分析:用输入矢量和相应的输 ...
- Delphi实现RGB色环的代码绘制(XE10.2+WIN764)
相关资料: http://blog.csdn.net/tokimemo/article/details/18702689 http://www.myexception.cn/delphi/215402 ...
- Pandas.plot 做图 demo(scatter,bar,pie)
#coding:utf-8import numpy as npimport matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['SimH ...
- CDH 修改配置注意事项
cdh 在使用时如果修改了配置文件,需要重启过时服务,而不是重启,重启过时服务才会修改配置文件