git配置ssh密鑰

git配置ssh密鑰


如果主機(當前登錄用戶)之前沒有git賬號,即添加第一個git賬號,並配置ssh密鑰時,

按照如下的步驟:

1 cd  ~/.ssh

2 ssh-keygen -t rsa -C '[email protected]'

3 cat id_rsa.pub

4 拷貝公鑰到git服務器上

5 測試:git clone [email protected]:liulian/mahout-0.9-custom.git

 

附加信息:

1

ssh-keygen -t rsa -C '[email protected]'

Generating public/private rsa key pair.

Enter file in which to save the key(/data/home/liulian/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):                (輸入密碼)

Enter same passphrase again:                               (再次輸入密碼)

Your identification has been saved in/data/home/liulian/.ssh/id_rsa.

Your public key has been saved in/data/home/liulian/.ssh/id_rsa.pub.

The key fingerprint is:

72:d2:d7:6e:35:68:e2:d8:78:5d:a6:99:4e:df:9e:0e [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

|                |

|                |

|                |

|      .   . .   |

|      o S o+ =  |

|       + * =B . |

|        o +OE   |

|         . +....|

|           . o+o|

+-----------------+

 

2

cat id_rsa.pub

ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEAvO04K2+6PEZjDj//5r6eVj19dBjqoAWWB/BtCdkeNWdb8cPQ6zrqQI3b+peBZn3abejI9nlVHEIcSRv+27V5nlRLL2euSZq1I/Qws9E4wNLkVg9MzO+omXuck7IZVt3DdwOKg6TQeajJD5xx+uq88Ln6VAp4n77mBNU40fEBj1GdmdB65cJWLgjfdtyUu5aW8mE8rzcuj+ahvzF4u+smVCeJnCW0frtWrMfNOSvx4J9QeYmwLI2QeBtW10HEFzsV9U0F5tMTE2CCHfRbDxkwVyAV9EsuLaOFdw1XMrNTOb+Q4d1FPOJj3k2WrOEqlYA0quoIioiaERCafVDZCcLaSw==liulian@gmail.com

 

3

git clone [email protected]:liulian/mahout-0.9-custom.git

Initialized empty Git repository in/data/home/liulian/project/mahout/mahout-0.9-custom/mahout-0.9-custom/.git/

The authenticity of host 'git.host.com(10.150.144.21)' can't be established.

RSA key fingerprint is58:c1:82:35:44:e8:6f:9d:3b:3e:db:c0:c4:9d:4e:cf.

Are you sure you want to continue connecting(yes/no)? yes

Warning: Permanently added 'git.host.com,10.150.144.21'(RSA) to the list of known hosts.

Enter passphrase for key'/data/home/liulian/.ssh/id_rsa':

remote: Counting objects: 3123, done.

remote: Compressing objects: 100% (2233/2233),done.

remote: Total 3123 (delta 739), reused 3120 (delta739)

Receiving objects: 100% (3123/3123), 5.77 MiB,done.

Resolving deltas: 100% (739/739), done.

 

 

 

 

如果主機(當前登錄用戶)之前已配置過一個git賬號,再配置新的git賬號時,按以下步驟。

 

1 cd ~/.ssh

2 生成密鑰

ssh-keygen -t rsa -C '[email protected]'

Generating public/private rsa key pair.

Enter file in which to save the key(/root/.ssh/id_rsa): linger_git

Enter passphrase (empty for no passphrase):09388296

3 查看公鑰,並拷貝到git服務器上

cat linger_git.pub

ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEAu7dQlbNyfTF2cc0jEhX9lJCjEaIRmxZxRxlkWS89zWzsclDY8D84otYo2ZwikyMXWbJmFh1yiQHkw6hFpMf+9aYJitRbnb6cztF38fUokNL6wbUrpHkkb9WOPa1hl4pCjt32PrR2U9rIClG9EV2GsHvsSuiOUgsCypG6DYL2UGEdlLeGfXs0Z1FpqD8GOnpMTetruTxponvCmmjPvlAW6gr/0h6/Ff/qaAuVPaBW3Oa3c9LWvKdhn6apdmUQTFsJpn1i0hOECsdVfXuOUj+9JAstVWj1Wh7yhGgVB9lOHOYRxSO/YZkQLvFX8RHLyj/vNhNoXuNCfw/m9R1jx4Myxw==[email protected]

4

vi config

Host git.host.com ##可以隨意命名,鏈接時使用這個名字 

HostName git.host.com

User git

# Port 22 

IdentityFile ~/.ssh/linger_git

 

5 測試

git clone [email protected]:liulian/weibo.git

Initialized empty Git repository in/root/liulian/git/weibo/weibo/.git/

Enter passphrase for key '/root/.ssh/linger_git':

remote: Counting objects: 106, done.

remote: Compressing objects: 100% (80/80), done.

remote: Total 106 (delta 23), reused 103 (delta 23)

Receiving objects: 100% (106/106), 190.24 KiB,done.

Resolving deltas: 100% (23/23), done.

 

PS:如果主機當前登錄用戶,沒有設置過任何git賬號,記得用上面的方法1,我曾經試過在這種情況直接用上面的方法2,竟然不行,後來用方法1就行了。

 

http://blog.163.com/zhou_411424/blog/static/1973621562013611640347/

http://chiyx.iteye.com/blog/1872447

 

本文作者:linger

本文鏈接:http://blog.csdn.net/lingerlanlan/article/details/46640219



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章