public key authentication(公钥认证)是对通过敲用户名、密码方式登录服务器的一种替代办法。这种方法更加安全更具有适应性,但是更难以配置。

传统的密码认证方式中,你通过证明你你知道正确的密码来证明你是你。证明你知道密码的唯一方式是你告诉服务器密码是什么。这意味着如果服务器被黑掉,或者欺骗,那么一个黑客攻击者就能学习到你的密码。

Public key authentication(公钥认证)解决了这个问题。你产生一个密钥对,该密钥对由一个public key(公钥)(每个人都可以知道的)和一个私钥(你负责该私钥的安全,不让任何人知道)。私钥可以用于产生签名(signatures)。一个由你的私钥派生出来的签名不能被任何不知道那个私钥的人所伪造,但同时任何知道你的公钥的人都能验证一个签名是否真正是由你的那个公钥、私钥所配对生成的签名!

你可以在自己的机器上创建上述公钥私钥key pair,随后你将公钥copy到服务器上。然后服务器询问你证明你是你时,PuTTY可以使用你的私钥产生一个签名并传给服务器。服务器就可以验证那个签名的真伪了(因为服务器有公钥),并且决定是否允许你登陆。现在如果服务器本身被黑掉或者被欺骗,那么攻击者无法获得你的私钥或者密码,他们仅仅能够获得一个签名而已。而签名本身是不能被重用的,所以他们什么也无法获得(原因是签名都是在秘钥交换过程中动态生成的)。

在这里有一个问题:如果你的私钥在你的本机明码保存的话,那么任何人只要能够访问到那个私钥文件那么他就能够冒充你来创建签名。所以他们因此将能够冒充你的身份登录到系统中去。因为这个原因,那么你的私钥通常在本地存储时是加密过的,这个私钥的加密就使用一个你设定的passphrase来加密的。为了创建一个签名,PuTTY必须要首先解密这个密码私钥,你必须通过输入正确的passphrase才能保证PuTTY能够正确解密私钥,进而创建签名。

上述过程使得public key authentication方式和单纯密码认证方式显得有些不是很方便:每次你登陆服务器,替代输入一个简单密码的方式,而必须输入一个很长的passphrase。一个解决方案是你使用一个authentication agent,该认证代理就是一个保存拥有已经被解密过的私钥并且据此在被请求时创建签名。Putty的认证代理被称为Pageant.当你开始一个windows session,你启动Pageant并且加载你的私有秘钥(需要输入一次passphrase)。其他的session,你就可以启动Putty任意次数,而由于Pageant会在不需你任何介入的情况下自动创建你的签名,而使得公钥认证使用更加方便一些。当你关闭了windows session, pageant shuts down,而永远不会将被解密过的私钥文件放到磁盘(仅仅存在于内存中)。很多人认为这是一个安全性和便利性的很好折中。

有多种公钥算法,最常用的是RSA,但也有其他的,比如DSA(DSS),美国联邦数字签名标准等。

在github使用中,如果你需要git push操作的话,很有可能就会出现:

GitHub: Permission denied (publickey).

的错误,原因就是你没有在github服务器上创建公钥,方法参考:

https://help.github.com/articles/generating-ssh-keys/

在上述github的命令执行过程中,

若执行ssh-add /path/to/xxx.pem是出现这个错误:Could not open a connection to your authentication agent,则先执行如下命令即可:

  ssh-agent bash

为了方便,将上述创建github公钥的过程罗列一下:

  • Check for SSH keys
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
  • Generate a new SSH key

ssh-keygen -t rsa -b  -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# :0f:f4:3b:ca::d6::a1:7d:f0::9d:f0:a2:db your_email@example.com
  • Add your key to the ssh-agent

# start the ssh-agent in the background
ssh-agent -s
# Agent pid
# start the ssh-agent in the background for windows
eval $(ssh-agent -s)
# Agent pid 59566
# ssh-add ~/.ssh/id_rsa

  • Add your SSH key to your account

To configure your GitHub account to use your SSH key:

Copy the SSH key to your clipboard. If your key is named id_dsa.pub, id_ecdsa.pub orid_ed25519.pub, then change the filename below from id_rsa.pub to the one that matches your key:

clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

http://the.earth.li/~sgtatham/putty/0.55/htmldoc/Chapter8.html

使用public key来做SSH authentication的更多相关文章

  1. git生成公钥public key并添加SSH key。git乌龟gerrit下推送git【server sent :publickey】

    一.key 码云链接:http://git.mydoc.io/?t=180845#text_180845 博客链接: 方式一:https://blog.csdn.net/xb12369/article ...

  2. Xshell配置ssh免密码登录-密钥公钥(Public key)与私钥(Private Key)登录【已成功实例】

    本文转自https://blog.csdn.net/qjc_501165091/article/details/51278696 ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口 ...

  3. Xshell配置ssh免密码登录-密钥公钥(Public key)

    1 简介 ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步: 1 ...

  4. Github 访问时出现Permission denied (public key)

    一. 发现问题: 使用 git clone 命令时出现Permission denied (public key) . 二. 解决问题: 1.首先尝试重新添加以前生成的key,添加多次,仍然不起作用. ...

  5. Xshell配置密钥公钥(Public key)与私钥(Private Key)登录

    ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步:1.生成密钥( ...

  6. Putty使用公钥认证时,报错:Disconnected: No supported authentication methods available(server sent:public key) 问题的解决

    Putty使用公钥认证时,按照常规方法设置,一直报错:Disconnected: No supported authentication methods available (server sent: ...

  7. Putty之public key ssh认证入门

    1.工作平台 客户端:Win2kEn Sp3,Putty Beta 0.53 服务器:RedHat72,OpenSSH_3.4p1 2.Putty简介 一个免费小巧的Win32平台下的ssh客户端.它 ...

  8. windows下git库的ssh连接,使用public key的方法

    在windows下进行项目开发,使用git,通过ssh方式与git库连接,而ssh方式用public key实现连接. 首先需要下载mygit,安装后使用git bash.git bash(有GUI界 ...

  9. How to use WinSCP with public key authentication

          http://www.techrepublic.com/blog/it-security/how-to-use-winscp-with-public-key-authentication/ ...

随机推荐

  1. HTML5 Cheat sheet PNG帮助手册(标签、事件、兼容)

    HTML5 Cheat sheet PNG帮助手册(标签.事件.兼容) 1.HTML5标签 2.HTML5事件 3.HTML5兼容 最新HTML5手册资料请参考:http://www.inmotion ...

  2. *args和**kw魔法参数

    学Python挺久了,现在才搞懂这个还是有点惭愧 *args:传入元组,无关键字 **kw:传入字典,有关键字 示例: *args **kw 一起使用时args的参数需在前:

  3. Java中List、Set和Map的区别--转载

    List按对象进入的顺序保存对象,不做排序或编辑操作.Set对每个对象只接受一次,并使用自己内部的排序方法(通常,你只关心某个元素是否属于Set,而不关心它的顺序--否则应该使用List).Map同样 ...

  4. IE6 png 透明--四种解决方法

    FF和IE7已经直接支持透明的png图了,下面这个主要是解决IE6下透明PNG图片有灰底的 方法一:定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了.(注意两处图片的路径 ...

  5. POJ 1759

    Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1236   Accepted: 547 Descriptio ...

  6. Wamp Mysql错误消息 语言设置

    Wamp Mysql错误消息 语言设置 http://my.oschina.net/wandershi/blog/264347 打开my.ini   找到 [wampmysqld] port = 33 ...

  7. nested pop animation can result in corrupted navigation bar

    nested pop animation can result in corrupted navigation barFinishing up a navigation transition in a ...

  8. java 如何从配置文件(.properties)中读取内容

    1.如何创建.properties文件 很简单,建立一个txt文件,并把后缀改成.properties即可 2.将.properties文件拷入src的根目录下 3..properties文件内容格式 ...

  9. node操作MongoDB数据库之插入

    在上一篇中我们介绍了MongoDB的安装与配置,接下来的我们来看看在node中怎样操作MongoDB数据库. 在操作数据库之前,首先应该像关系型数据库一样建个数据库把... 启动数据库 利用命令提示符 ...

  10. 在Jmeter中使用自定义编写的Java测试代码

    我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","Java ...