如果主机(当前登录用户)之前没有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