Git SSH Configuration - tenji/ks GitHub Wiki

SSH和HTTPS方式对比

Waiting for editing...

SSH配置和使用

  1. 设置username和email
    $ git config --global user.name "tenji"
    $ git config --global user.email "[email protected]"
  2. 生成SSH Key
    $ ssh-keygen -t rsa -C "[email protected]"
    连续三个回车之后,可以得到两个文件:id_rsaid_rsa.pub
  3. 添加SSH Key到GitHub
    登陆GitHub,把id_rsa.pub文件里的内容添加到SSH Keys中,路径:Setting >> SSH and GPS keys >> New SSH key
  4. 测试是否可用
    $ ssh -T [email protected]
    看到以下提示说明SSH已经可用:

Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
Hi tenji! You've successfully authenticated, but GitHub does not provide shell access.

  1. 修改已有HTTPS工程的URL
    修改.git文件夹下config中的url
    修改前:

[remote "origin"]
 url = https://github.com/tenji/ks.git
 fetch = +refs/heads/:refs/remotes/origin/

  修改后:

[remote "origin"]
 url = [email protected]:tenji/ks.git
 fetch = +refs/heads/:refs/remotes/origin/