概述:

  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公钥认证登录的更多相关文章

  1. Linux配置SSH公钥认证与Jenkins远程登录进行自动发布

    公钥认证,是使用一对加密字符串,一个称为公钥(public key), 任何人都可以看到其内容,用于加密:另一个称为密钥(private key),只有拥有者才能看到,用于解密. 在使用jenkins ...

  2. ssh公钥认证原理及设置root外的其他用户登录ssh

    1)创建其他用户 useradd [-d 登录目录] [-G ssh][用户名]  一定要将用户添加到ssh组不然无法没有权限登录ssh 2)设置ssh不允许root登录 vi /etc/ssh/ss ...

  3. SSH公钥认证+优化

    一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥   ...

  4. [svc][op]SSH公钥认证+优化

    一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥 二 ...

  5. 转: SSH 公钥认证

    转: http://blog.knownsec.com/2012/05/ssh-%E5%85%AC%E9%92%A5%E8%AE%A4%E8%AF%81/ SSH 公钥认证 2012-05-15 简介 ...

  6. SSH公钥认证(码云)

    开发者向码云版本库写入最常用到的协议是 SSH 协议,因为 SSH 协议使用公钥认证,可以实现无口令访问,而若使用 HTTPS 协议每次身份认证时都需要提供口令.使用 SSH 公钥认证,就涉及到公钥的 ...

  7. 安装gitolite,并ssh公钥无密码登录

    安装gitolite,并ssh公钥无密码登录 gitolite是管理git版本库的一种方案,它将git版本库的管理信息放在了一个特殊git版本库里.gitolite与linux操作系统集成了,需要使用 ...

  8. 使用SecureCRT设置linux系统登录的ssh公钥认证

    1.修改ssh配置文件/etc/ssh/sshd_configRSAAuthentication yes                             //使用RSA加密算法PubkeyAu ...

  9. linux配置ssh公钥认证,打通root用户的免密码输入的scp通道

    1.ssh-keygen ssh-keygen是unix-like系统的一个用来生成.管理ssh公钥和私钥的工具. 2.用法 常用的重要的选项有: -b num   指定生成多少比特长度的key,单位 ...

随机推荐

  1. 虚拟局域网VLAN

    6.5.1配置路由器广域网端口的PPP封装 (1)配置路由器A: Router>enable Router#config Router_config#hostname Router-A Rout ...

  2. 9、XAML名称空间详解

    XAML命名空间 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      ...

  3. ServiceStack.OrmLite 调用存储过程

    最近在做关于ServiceStack.OrmLite调用存储过程时,有问题.发现ServiceStack.OrmLite不能调用存储过程,或者说不能实现我想要的需求.在做分页查询时,我需要传入参数传出 ...

  4. matlab实现复合梯形法则

    复合梯形法则: function int_f = CompoundEchelon( f, a, b, m ) % input : f : function handler % a : the lowe ...

  5. 顺序容器:vector,deque,list

    1.顺序容器:vector,deque,list 容器类共享公共接口,只要学会其中一种类型就能运用另一种类型.每种容器提供一组不同的时间和功能这种方案,通常不需要修改代码,秩序改变类型声明,每一种容器 ...

  6. LintCode-Word Search II

    Given a matrix of lower alphabets and a dictionary. Find all words in the dictionary that can be fou ...

  7. Handlebars模板引擎中的each嵌套及源码浅读

    若显示效果不佳,可移步到愚安的小窝 Handlebars模板引擎作为时下最流行的模板引擎之一,已然在开发中为我们提供了无数便利.作为一款无语义的模板引擎,Handlebars只提供极少的helper函 ...

  8. BAT CMD 批处理文件脚本 -1

    http://www.cnblogs.com/linglizeng/archive/2010/01/29/Bat-CMD-ChineseVerion.html 1.               综述 ...

  9. 【转载】OpenStack Swift学习笔记

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:崔炳华      原文地址:http://blog.csdn.net/i_ch ...

  10. 解决Maven默认仓库没有的jar下载(二)

    前言: 在 “解决Maven不能下载“oracle.aspectjweaver.com.springsource.net.sf.cglib”jar(http://www.cnblogs.com/wql ...