git-ssh 配置和使用

作者: 高高叔叔 | 来源:发表于2017-05-03 00:48 被阅读426次

    现在很多都是和git进行项目管理 但我们用HTTP 协议进行push的时候总是会遇到一些问题比如文件过大之类的。 决定用了SSH 协议。

    设置Git的user name和email
    $ git config --global user.name "humingx"
     $ git config --global user.email "humingx@yeah.net"
    
    生成密钥
    $ ssh-keygen -t rsa -C "humingx@yeah.net"
    

    连续3个回车。如果不需要密码的话。
    最后得到了两个文件:id_rsa和id_rsa.pub。

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/zhengmingxiang/.ssh/id_rsa): 
    Created directory '/Users/zhengmingxiang/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /Users/zhengmingxiang/.ssh/id_rsa.
    Your public key has been saved in /Users/zhengmingxiang/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:GT1GWBv7F7VJ5PfPRSFkSwoAkxHQUVe5fPvnEdlDJgg 13365068888@sina.cn
    The key's randomart image is:
    +---[RSA 2048]----+
    |   .o*Bo.E=.o=.+.|
    |     o. ooo== =.+|
    |        . Bo.o.*o|
    |         + = .+o=|
    |        S   o o++|
    |             o .=|
    |              ..o|
    |               .o|
    |               .o|
    +----[SHA256]-----+
    zhengmingxiangdeMacBook-Pro:~ zhengmingxiang$ 
    

    如果不是第一次overwrite选择y

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/zhengmingxiang/.ssh/id_rsa): 
    /Users/zhengmingxiang/.ssh/id_rsa already exists.
    Overwrite (y/n)? 
    
    添加密钥到ssh-agent
    $ ssh-add ~/.ssh/id_rsa
    

    得到结果,这是后面要用到的文件的路径

    Identity added: /Users/zhengmingxiang/.ssh/id_rsa (/Users/zhengmingxiang/.ssh/id_rsa)
    
    登陆Github, 添加 ssh

    前往路径把id_rsa.pub文件里的内容复制到这里管理密钥的key里面(相信大家可以自己找到添加的位置)。

    测试
    ssh -T git@github.com
    

    你将会看到:

    The authenticity of host 'github.com (192.30.255.112)' can't be established.
    RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
    Are you sure you want to continue connecting (yes/no)? yes
    

    选择 yes

    Hi godwar10! You've successfully authenticated, but GitHub does not provide shell access.
    

    成功了。现在就可以使用ssh创建新仓库了

    touch README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin git@kd.gdgs.com:zhengmx_test.com/ww.git
    git push -u origin master
    

    相关文章

      网友评论

        本文标题:git-ssh 配置和使用

        本文链接:https://www.haomeiwen.com/subject/rdahtxtx.html