git配置ssh密鑰

來源:互聯網
上載者:User

標籤: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+[email protected]

 

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



git配置ssh密鑰

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.