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.pubid_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. Unity使用外部版本控制SVN

    原地址:http://www.cnblogs.com/realtimepixels/p/3652146.html Using External Version Control Systems with ...

  2. ubuntu修改ip、网关、dns等

    一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...

  3. 用 VIPER 构建 iOS 应用架构(1)

    [编者按]本篇文章由 Jeff Gilbert 和 Conrad Stoll 共同编写,通过构建一个基础示例应用,深入了解 VIPER,并从视图.交互器等多个部件理清 VIPER 的整体布局及思路.通 ...

  4. HTML5 webSQL

    https://www.ibm.com/developerworks/cn/web/1108_zhaifeng_websqldb/   <!DOCTYPE HTML> <html&g ...

  5. jquey ajax 无刷新提交form

    http://bbs.csdn.net/topics/380237868 $.ajax({ type: "POST", url:ajaxCallUrl, data:$('#your ...

  6. Raphaël 是一个小型的 JavaScript 库,用来简化在页面上显示向量图的工作。你可以用它在页面上绘制各种图表、并进行图片的剪切、旋转等操作。

    点这里 在线效果演示:http://raphaeljs.com/pie.html http://raphaeljs.com github: https://github.com/DmitryBaran ...

  7. ubuntu安装hive

    1.安装mysql,可参考下面链接 http://www.cnblogs.com/liuchangchun/p/4099003.html 2.安装hive,之前,先在mysql上创建一个hive,数据 ...

  8. (4)用opengl读入off文件生成可执行文件把模型显示出来(未完待续)

    ·找了好几个程序,好像都达不到我的要求,去教程里看看吧! 在往上抛出了这问题,好几天才有人回答,我已经找到程序了 正好的他的分析对我分解程序很有用 这是一个难度比较高的 首先你要分析.off文件结构, ...

  9. Newtonsoft.Json.dll

    代码 using System; DoNet2.0 需要借助于Newtonsoft.Json.dll using System.IO; using System.Text; using Newtons ...

  10. Shell练习 行列转换

    原题:https://leetcode.com/problems/transpose-file/Given a text file file.txt, transpose its content. Y ...