0. launch GitBash
1. chk OpenSSH/OpenSSL are installed
$ ssh -v
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 ...
$ cd //go back user home folder
$ pwd
$ cd .ssh
[ $ cd ~/.ssh ]
$ ls
id_rsa id_rsa.pub known_hosts
* id_rsa is the private key
* id_rsa is the public key
* id --> identifier for short
2. $ ssh-keygen
[ 3. notepad ~/.ssh/config , 預設的組態檔
加入
Host bitbucket.org
IdentityFile ~/.ssh/id_rsa
"...
The second line is indented.
That indentation (a single space) is important, so make sure you include it.
..."
IdentityFile 的那一行開頭必須有一個空白, 之後緊接著IdentityFile path-to-privatekey
]
4. $ ssh-add -l
Could not open a connection to your authentication agent
-->
need to start ssh-agent before you run the ssh-add command:
$ eval `ssh-agent -s` # need to use eval instead of just ssh-agent
$ ssh-add path-to-target-privatate-key
path-to-target-privatate-key 代表密鑰檔案路徑
會蓋過預設組態檔的設定
[例] /c/myProjs/sshkeys/privkey-for-bitbucket
account settings --> ssh
*** take care not to wrap the lines
6. 更改既存的git config, 將https改為ssh
$ cat .git/config
[core]
...
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://username@bitbucket.org/teamid/repo1.git
[branch "master"]
remote = origin
merge = refs/heads/master
--> url = ssh://git@bitbucket.org/username/repo1.git
https://accountname@bitbucket.org/accountname/reponame.git
--> ssh://git@bitbucket.org/accountname/reponame.git
https://accountname@bitbucket.org/teamid/reponame.git
--> ssh://git@bitbucket.org/teamid/reponame.git
//=== 讓 Git Bash 啟動時帶入 ssh-agent
http://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent
1. notepad .bashrc
#!/bin/bash
eval `ssh-agent -s`
ssh-add
ssh-add without paramaters
--> ~/.ssh/id_rsa
for customized location of the private key
--> ssh-add path-to-private-key
2. Restart GitBash (Msysgit)
$ man ssh-add
""" ...
-L Lists public key parameters of all identities currently repre?
sented by the agent.
-l Lists fingerprints of all identities currently represented by the
agent.
... """
$ man ssh-agent
""" ...
a program to hold private keys used for public key authenti?
cation (RSA, DSA, ECDSA). The idea is that ssh-agent is started in the
beginning of an X-session or a login session, and all other windows or
programs are started as clients to the ssh-agent program. Through use of
environment variables the agent can be located and automatically used for
authentication when logging in to other machines using ssh(1).
..."""
//===
沒有留言:
張貼留言