Git 学习笔记 -- Set up SSH for Git
2014-10-03 01:40
459 查看
Step 1. Read a quick overview of SSH concepts
To use SSH with Bitbucket, you create an SSH identity. An identity consists of a private and a public key which together are a key pair. The private key resides on your local computer and the public you upload to your Bitbucket account. Once youupload a public key to your account, you can use SSH to connect with repositories you own and repositories owned by others, provided those other owners give your account permissions. By setting up SSH between your local system and the Bitbucket server, your
system uses the key pair to automate authentication; you won't need to enter your password each time you interact with your Bitbucket repository.
There are a few important concepts you need when working with SSH identities and Bitbucket
You cannot reuse an identity's public key across accounts. If you have multiple Bitbucket accounts, you must create multiple identities and upload their corresponding public keys to each individual account.
You can associate multiple identities with a Bitbucket account. You would create multiple identities for the same account if, for example, you access a repository from a work computer and a home computer. You might create multiple identities if
you wanted to execute DVCS actions on a repository with a script – the script would use a public key with an empty passphrase allowing it to run without human intervention.
RSA (R. Rivest, A. Shamir, L. Adleman are the originators) and digital signature algorithm (DSA) are key encryption algorithms. Bitbucket supports both types of algorithms. You should create identities
using whichever encryption method is most comfortable and available to you.
Step 2. Check if you have existing default Identity
The Git Bash shell comes with an SSH client. Do the following to verify your installation:Double-click the Git Bash icon to start a terminal session.
Enter the following command to verify the SSH client is available:
manthony@MANTHONY-PC ~ $ ssh -v OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 usage: ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-e escape_char] [-F configfile] [-i identity_file] [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R [bind_address:]port:host:hostport] [-S ctl_path] [-w local_tun[:remote_tun]] [user@]hostname [command]
If you have
sshinstalled, go to the next step.
If you don't have
sshinstalled, install it now with your package manager.
List the contents of your
~/.sshdirectory.
If you have not used SSH on Bash you might see something like this:
manthony@MANTHONY-PC ~ $ ls -a ~/.ssh ls: /c/Users/manthony/.ssh: No such file or directory
If you have a default identity already, you'll see two
id_*files:
manthony@MANTHONY-PC ~ $ ls -a ~/.ssh . .. id_rsa id_rsa.pub known_hosts
In this case, the default identity used RSA encryption (
id_rsa.pub). If you want to use an existing default identity for your Bitbucket account, skip the next section and go to create
a config file.
Step 3. Set up your default identity
By default, the system adds keys for all identities to the /Users/yourname/.sshdirectory. The following procedure creates a default identity.
Open a terminal in your local system.
Enter
ssh-keygenat the command line.
The command prompts you for a file to save the key in:
manthony@PHOENIX ~ $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Documents and Settings/manthony/.ssh/id_ rsa):
Press enter to accept the default key and path,
/c/Documents and Settings/manthony/.ssh/id_rsa, or you can create a key with another name.
To create a key with a name other than the default, specify the full path to the key. For example, to create a key called
my-new-ssh-key, you would enter a path like this at the prompt:
manthony@PHOENIX ~ $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Documents and Settings/manthony/.ssh/id_ rsa): /c/Documents and Settings/manthony/My Documents/keys/my-new-ssh-key
Enter and renter a passphrase when prompted.
Unless you need a key for a process such as script, you should always provide a passphrase.
The command creates your default identity with its public and private keys. The whole interaction looks similar to the following:
manthony@MANTHONY-PC ~ $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/manthony/.ssh/id_rsa): Created directory '/c/Users/manthony/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/manthony/.ssh/id_rsa. Your public key has been saved in /c/Users/manthony/.ssh/id_rsa.pub. The key fingerprint is: e7:94:d1:a3:02:ee:38:6e:a4:5e:26:a3:a9:f4:95:d4 manthony@MANTHONY-PC manthony@MANTHONY-PC ~ $
List the contents of
~/.sshto view the key files.
You should see something like the following:
id_rsa.pub) and one for the private key (for example,
id_rsa).
More information can be found here: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
相关文章推荐
- Set up SSH for Git and Mercurial on Mac OSX/Linux
- 【Git学习笔记】安装 SSH keys for Gitbash
- Git for Android Studio 学习笔记
- Git与GitHub学习笔记(七)Windows 配置Github ssh key
- SSH学习笔记之hibernate中的set排序以及struts中的token
- For和Set参数学习笔记
- Set Up Git Server through SSH Connection
- git学习笔记 --- Warning: the ECDSA host key for 'myserver' differs from the key for the IP address 192.。
- Set up ssh password less key across all the servers for genesys service account
- web开发-Windows系统下使用git for Windows软件-学习笔记六
- Python3学习笔记【基础3--list,tuple,if条件判断,for/while循环,dict字典,set集合】
- Set up git server on ubuntu using ssh protocol(已经测试可以)
- 【DirectX 11 SDK 学习笔记】set up window
- XSL学习笔记3 XSLT的模板规则<xsl:value-of>和<xsl:for-each>
- Ubuntu学习笔记:通过ssh远程登录服务器
- A guide to Matlab for Beginners and Experienced Users——学习笔记【1】
- 小五思科技术学习笔记之SSH 推荐
- 学习EJB for JBoss 3.2笔记(2)测试jsp
- SSH学习问题笔记1