github生成SSH公钥

来源:互联网 发布:二战苏联远东部队知乎 编辑:程序博客网 时间:2024/06/06 07:05

在OS X Yosemite 10.10.3安装最新版本Xcode,在terminal下可以发现git已经被安装。

~ mesut$ git --versiongit version 2.3.2(Apple Git-55)

之前就已经注册并且使用Github了,不过一直都是在window 系统下远程管理。

现在开始设置Mac管理Github,有一点需要知道的是本地的git仓库和Github服务器之间是通过ssh加密的。

在终端执行

ozil:tmp mesut$ ssh -vOpenSSH_6.2p2, OSSLShim 0.9.8r8Dec 2011usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]           [-D [bind_address:]port] [-e escape_char] [-F configfile]           [-I pkcs11] [-i identity_file]           [-L [bind_address:]port:host:hostport]           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]           [-R [bind_address:]port:host:hostport] [-S ctl_path]           [-W host:port] [-w local_tun[:remote_tun]]           [user@]hostname [command]

明显Mac已经安装了ssh。

1:创建SSH Key

ozil:tmp mesut$ cd ~ozil:~ mesut$ pwd/Users/mesutozil:~ mesut$ cd .ssh-bash: cd: .ssh: No such file or directoryozil:~ mesut$

进入当前的用户目录,波浪线表示的是当前目录。判断是否已经安装了.ssh,避免默认安装会覆盖之前安装的。明显当前目录没有该文件

执行创建 ssh key

ssh-keygen -t rsa -C youremail@example.com(你的Github登陆名)

接着都是回车,选择默认的目录,默认的密码即可

Generatingpublic/privatersa key pair.Enter file in which to save the key (/Users/mesut/.ssh/id_rsa):     Created directory '/Users/mesut/.ssh'.Enter passphrase (empty forno passphrase): Enter same passphrase again: Your identification has been saved in /Users/mesut/.ssh/id_rsa.Yourpublickey has been saved in /Users/mesut/.ssh/id_rsa.pub.

接着可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对

ozil:~ mesut$ cd .sshozil:.ssh mesut$ lsid_rsa      id_rsa.pub

title:可以顺便填名字

key:在Key文本框里粘贴id_rsa.pub文件的内容

点击add key 配置完成

由于之前没有配置用户名,所以首次commit会有提示,自动建立设置方式 git config --global user.name Your Name git config --global user.email email@example.com
1 0
原创粉丝点击