帮忙解释29题!如何用c public privatekey 和private key 发信息,过程是怎样!

官方说明:/articles/generating-ssh-keys/
1,为Github账户设置SSH key
文章地址://setup-github-ssh-key/
什么是SSH key
一直使用SSH连接服务器,但是对它的原理却不太了解。这次设置Octopress的时候,需要使用SSH 方式连接Github, 正好对SSH的工作方式做了下了解。(好像Github推荐使用HTTPS的方式访问repo, 以前Github受到过,之后升级了SSH key的安全措施,https方式视乎更方便安全,不过Octopress的设置文档中,我并没有找到怎么使用HTTPS连接Github)简单来说,SSH提供了两种级别的安全验证:
第一种级别是基于密码的安全验证,知道账号和密码,就可以登陆到远程主机。Team的开发工作中,就是使用这种方式登陆编译服务器,或者开发机器。因为是在内网中,这种级别的安全验证已经足够了。
第二种级别是基于机制的安全验证,原理如下图所示:
其优点在于无需共享的通用密钥,解密的私钥不发往任何用户。即使公钥在网上被截获,如果没有与其匹配的私钥,也无法解密,所截获的公钥是没有任何用处的。
产生SSH key
根据Github提供的help文档,具体过程如下
$ cd ~/.ssh
使用ssh-keygen产生新的key
$ ssh-keygen -t rsa -C "your_"
使用默认的文件名直接enter, 按提示输入密码(如果不提供密码,SSH将无密码连接,如果private key泄露可能会有安全问题)
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
密匙产生成功
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_
上传public key到Github账户
登录github
点击右上方的Accounting settings图标
选择 SSH key
点击 Add SSH key
在出现的界面中填写SSH key的名称,填一个你自己喜欢的名称即可,然后将上面拷贝的~/.ssh/id_rsa.pub文件内容粘帖到key一栏,在点击&add key&按钮就可以了。添加过程github会提示你输入一次你的github密码
设置SSH使用HTTPS的403端口
在局域网中SSH的22端口可能会被防火墙屏蔽,可以设置SSH使用HTTPS的403端口。
测试HTTPS端口是否可用
$ ssh -T -p 443 git@
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
编辑SSH配置文件 ~/.ssh/config 如下:
测试是否配置成功
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
多个Github账号的SSH key切换
如果在一台机器上要登陆多个Github账户,需要一些配置,虽然现在并没有用到,但是先记下来以备不时之需,过程参看。
在github上,建立一个项目test,去主页查看可以看到
如果使用HTTPS:
Create a new repository on the command line
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin /guochy2012/test.git
git push -u origin master
Push an existing repository from the command line
git remote add origin /guochy2012/test.git
git push -u origin master
如果采用SSH:
Create a new repository on the command line
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin :guochy2012/test.git
git push -u origin master
Push an existing repository from the command line
git remote add origin :guochy2012/test.git
git push -u origin master
使用HTTPS需要每次输入密码,SSH则不用,但SSH需要配置密钥 。
关于怎么产生密钥可以参见《》一文
3,github地址 从https改成ssh
打开命令行工具,运行&git remote set-url origin&例如:
$ git remote set-url origin git@github.com:user/repo.git
然后再次 commit,如果出现类似:
Permission denied (publickey).
字样,那么说明你的 SSH key 没有设置或已经失效(譬如升级到 Mountain Lion 系统后),请重新参照上文的进行设置即可。
4,执行pull时报错
wangkongming@AY170503Z:~/github/collect$ git pullWarning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
WARNING: UNPROTECTED PRIVATE KEY FILE!
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0644 for '/home/wangkongming/.ssh/id_rsa' are too open.It is recommended that your private key files are NOT accessible by others.This private key will be ignored.bad permissions: ignore key: /home/wangkongming/.ssh/id_rsaPermission denied (publickey).fatal: The remote end hung up unexpectedly
答案:/questions/1556119/ssh-private-key-permissions-using-git-gui-or-ssh-keygen-are-too-open
是因为给 id_rsa的权限太高了,改成700就可以了。也有人说600
You changed the permissions on the whole directory, which I agree with Splash is a bad idea. If you can remember what the original permissions for the directory are, I would try to set them back to that and then do the following
chmod 700 id_rsa
inside the .ssh folder. That will set the id_rsa file to rwx (read, write, execute) for the owner (you) only, and zero access for everyone else.
If you can't remember what the original settings are, add a new user and create a set of SSH keys for that user, thus creating a new .ssh folder which will have default permissions. You can use that new .ssh folder as the reference for permissions to reset your .ssh folder and files to.
If that doesn't work, I would try doing an uninstall of msysgit, deleting ALL .ssh folders on the computer (just for safe measure), then reinstalling msysgit with your desired settings and try starting over completely (though I think you told me you tried this already).
Edited: Also just found this link via Google --&&While it's targeted at linux, it might help since we're talking liunx permissions and such.
======================================
以下是自己在使用git时,总结的:
1,查看当前项目远程分支的路径
git remote -v
阅读(...) 评论()KeyGen sender现代密码学怎样翻译a large prime number,还有这个怎样翻译啊_百度知道
KeyGen sender现代密码学怎样翻译a large prime number,还有这个怎样翻译啊
非对称加密用到两个秘钥key1和key2;用key2加密的原文只能用key1解密。非对称加密算法已经证明,在很多应用场合下(例如数字签名)需要将这两个密码中的一个公开(1)a large prime的意思是“ 一个非常大素数”【背景】在非对称加密中。被公开(public to all)的key 称为为公钥。在生成公钥和私钥时使用a large prime(一个非常的素数)(2)public to all 的意思“公开”【背景】这个词也和非对称加密有关;被私藏的key称为私钥,即素数越大,公钥(public key)和私钥(private key)都是素数的函数,破解难度越大。用key1加密的原文只能用key2来解密。简单地讲。通常,另一个不公开:要猜出(或破解)用公钥或密码加密的原文的难度与素数大小有关
其他类似问题
为您推荐:
现代密码学的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁版权所有 京ICP备号-2
迷上了代码!

我要回帖

更多关于 private public 区别 的文章

 

随机推荐