SSH公钥认证登录
概述:
SSH登录的认证方式分为两种,一种是使用用户名密码的方式,另一种就是通过公钥认证的方式进行访问,
用户名密码登录的方式没什么好说的,本文主要介绍通过公钥认证的方式进行登录。
思路:
在客户端生成公钥和私钥,将公钥上传至服务器上后进行无密码访问。
环境:
客户机:192.168.129.129
服务机:192.168.129.128
步骤:
(1)在客户端生成公钥与私钥
root@kali2:~/.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:
e9::e1:c9::9e:cb:1e:ec::8c:e9:9a:a5::ff root@kali2
The key's randomart image is:
+---[RSA ]----+
| |
| |
| . |
| + . |
| S+o |
| +o*o. |
| ..O =. |
| X.o .. |
| =...E. |
+-----------------+
(2)查看已生成的公钥私钥
root@kali2:~/.ssh# ls -l
total
-rw------- root root Jul : id_rsa
-rw-r--r-- root root Jul : id_rsa.pub
-rw-r--r-- root root Jul : known_hosts
(3)将公钥id_rsa.pub发送到服务器上
root@kali2:~/.ssh# scp -r /root/.ssh/id_rsa.pub root@192.168.129.128:/root/.ssh
root@192.168.129.128's password:
id_rsa.pub % .4KB/s :
(4)进入服务器的/root/.ssh目录下,将id_rsa.pub内容重定向到同目录下的文件authorized_keys里
[root@localhost .ssh]# ls
id_rsa.pub known_hosts
[root@localhost .ssh]# touch authorized_keys
[root@localhost .ssh]# ls
authorized_keys id_rsa.pub known_hosts
[root@localhost .ssh]# cat id_rsa.pub >> ./authorized_keys
[root@localhost .ssh]# ls -l
total
-rw-r--r--. root root Jul : authorized_keys
-rw-r--r--. root root Jul : id_rsa.pub
-rw-r--r--. root root Jul : known_hosts
(5) 此时在客户机访问服务机可不输入密码了
root@kali2:~/.ssh# ssh 192.168.129.128
Last failed login: Tue Jul :: CST from 192.168.129.129 on ssh:notty
There was failed login attempt since the last successful login.
Last login: Tue Jul :: from 192.168.129.129
[root@localhost ~]#
注意事项:
在使用公钥认证之前,先检查一下服务器的ssh配置文件/etc/ssh/sshd_config
RSAAuthentication yes # 启用 RSA 认证,默认为yes
PubkeyAuthentication yes # 启用公钥认证,默认为yes 如果安全性要求高,修改一下服务器的配置文件/etc/sshd/sshd_config,
禁用密码登录,只能通过公钥方式登录。
PasswordAuthentication no
SSH公钥认证登录的更多相关文章
- Linux配置SSH公钥认证与Jenkins远程登录进行自动发布
公钥认证,是使用一对加密字符串,一个称为公钥(public key), 任何人都可以看到其内容,用于加密:另一个称为密钥(private key),只有拥有者才能看到,用于解密. 在使用jenkins ...
- ssh公钥认证原理及设置root外的其他用户登录ssh
1)创建其他用户 useradd [-d 登录目录] [-G ssh][用户名] 一定要将用户添加到ssh组不然无法没有权限登录ssh 2)设置ssh不允许root登录 vi /etc/ssh/ss ...
- SSH公钥认证+优化
一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥 ...
- [svc][op]SSH公钥认证+优化
一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥 二 ...
- 转: SSH 公钥认证
转: http://blog.knownsec.com/2012/05/ssh-%E5%85%AC%E9%92%A5%E8%AE%A4%E8%AF%81/ SSH 公钥认证 2012-05-15 简介 ...
- SSH公钥认证(码云)
开发者向码云版本库写入最常用到的协议是 SSH 协议,因为 SSH 协议使用公钥认证,可以实现无口令访问,而若使用 HTTPS 协议每次身份认证时都需要提供口令.使用 SSH 公钥认证,就涉及到公钥的 ...
- 安装gitolite,并ssh公钥无密码登录
安装gitolite,并ssh公钥无密码登录 gitolite是管理git版本库的一种方案,它将git版本库的管理信息放在了一个特殊git版本库里.gitolite与linux操作系统集成了,需要使用 ...
- 使用SecureCRT设置linux系统登录的ssh公钥认证
1.修改ssh配置文件/etc/ssh/sshd_configRSAAuthentication yes //使用RSA加密算法PubkeyAu ...
- linux配置ssh公钥认证,打通root用户的免密码输入的scp通道
1.ssh-keygen ssh-keygen是unix-like系统的一个用来生成.管理ssh公钥和私钥的工具. 2.用法 常用的重要的选项有: -b num 指定生成多少比特长度的key,单位 ...
随机推荐
- HDU 2669 第六周 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the ...
- [转]adb pull Permission denied及no such file错误
adb pull Permission denied及no such file错误 http://www.the8m.com/blog/article/javadk/adbpull.html XP系 ...
- sql Mirroring
http://www.codeproject.com/Articles/109236/Mirroring-a-SQL-Server-Database-is-not-as-hard-as http:// ...
- 输入adb shell 时 提示error: more than one device and emulator
第一种情况:确实用多个设备或者模拟器 解决办法:(指定连接某一个设备或者模拟器) 1.获取模拟器/设备列表 adb devices 2.指定device来执行adb shell adb -s ...
- 在云服务器搭建WordPress博客(五)创建和管理文章分类
不同主题的文章划分到不同的分类,有助于访客寻找他们想要的内容,提高用户体验.所以,为你的网站创建文章分类是很有必要的.那么,WordPress系统如何创建和管理文章分类呢?今天倡萌就简单介绍一下. 创 ...
- ZedGrap控件绘制图表曲线
问题描述: 使用C#中ZedGrap控件绘制图表曲线图 ZedGrap 介绍说明: 安装ZedGrap控件 ZedGraph控件dll文件: 添加ZedGraph控件,首先在新建立的C#图像工 ...
- 【BestCoder】【Round#29】
T1 啊……a^b 与 c^d比较大小,我们可以两边取对数,转化成 log(a^b)=b*log(a) 和d*log(c) 这样就能直接算了……然后稍微搞一下精度什么的就A了=.= //BC #29 ...
- 剑指offer--面试题6
题目:由前序.中序遍历序列重建二叉树 虽然思路能想到,但是实际写却无从下手...下面重现作者代码,多多实践... #include<exception> //首先定义二叉树节点 struc ...
- PhyreEngine3.8 MSAA resolution
There is something wrong in PhyreEngine 3.8 to fullfill MSAA, actually, I think it is eqaa You have ...
- [转载]Spring Beans Auto-Wiring
Autowiring Modes You have learnt how to declare beans using the <bean> element and inject < ...