git uses SSH keys and HTTPS two authentication methods to summarize

Source: Internet
Author: User
Tags diff

In the repository of SSH and HTTPS mode is different, specifically, the URL information is different, but the actual authentication mechanism is different. When this key is established, the use of SSH does not actually require re-authentication, and HTTPS will need to enter a password each time. "Help.github-ssh Key passphrases" also said that SSH is more convenient and more secure, do not need to enter a long password.

I went to see the. git/config under the Repo directory, and sure enough, my URL is in HTTPS form.

123 
[remote "origin"]fetch = + refs/heads/*:refs/remotes/origin/*url = https://[email protected]/username/projectname.git

Because the URL of the remote repository is HTTPS, it is estimated that my Git clone was caused by an HTTPS link.

So the problem is here, every time is very inconvenient, you have to enter the user name and password.

In order to use the SSH public key authentication method, I changed the URL of config to the following

123 
[remote "origin"]fetch = + refs/heads/*:refs/remotes/origin/*url = [email protected]:username/projectname.git

This way I can use the SSH public key authentication without having to enter the user name and password, which is not only convenient, but also more secure.

Http://www.cnblogs.com/hanxi/archive/2012/07/31/2616628.html

Git has a tool called git config that allows you to get and set configuration variables that control all aspects of Git's look and operation. These variables can be stored in three different locations:

1./etc/gitconfig file: Contains values that apply to all users of the system and to all libraries. If you pass the parameter option '--system ' to git config, it will explicitly read and write this file.

2.~/.gitconfig file: Specific to your users. You can make Git Read or write this particular file by passing the--global option.

3. config file (i.e.. git/config) in the git directory : Regardless of what library you are currently using, point to that single library. Each level overrides the value of the previous level. Therefore, the value in. git/config overrides the same value in the/etc/gitconfig.

In Windows systems,git looks for . gitconfig files in the $HOME directory (for most people, under C:\Documents and Settings\ $USER). It will also look for /etc/gitconfig, although it is relative to the Msys root directory. This could be anywhere you decide to install git when you run Setup in Windows .

Two. Your identity (Your identity)

2.1 The first thing to do when you install Git is to set your user name and e-mail address. This is important because each git commit uses that information. It is permanently embedded in your submission:

$ git config--global user.name "John Doe"

$ git config--global user.email [email protected]

Again, you just need to do this one time setting. If you pass the --global option, git will always use that information to handle everything you do in the system. If you want to use a different name or e-mail address in a particular project , you can run the command in that project without --global the option.

2.2 Your editor (Your editor)

Now that your logo is set, you can configure your default text editor, whichgit will use when you need to enter some messages. By default,git uses your system's default editor, which is usually either VI or vim. If you want to use a different text editor, such as Emacs, you can do the following:

$ git config--global core.editor emacs

2.3 Your comparison tools (Your Diff tool)

Another useful option that you might want to configure is the default comparison tool, which is used to resolve conflicts when merging. For example, you want to use Vimdiff:

$ git config--global merge.tool vimdiff

  Git can accept kdiff3, Tkdiff, meld, Xxdiff, emerge, Vimdiff, Gvimdiff, Ecmerge, and Opendiff as valid merge tools. You can also set up a customized tool, and see Chapter 7 For more information on this.

2.4 Check your settings (Checking Your Settings)

If you want to check your settings, you can use the git config--list command to list all the settings that git can find there :

$ git config--list

User.name=scott Chacon

[Email protected]

Color.status=auto

Color.branch=auto

Color.interactive=auto

Color.diff=auto

...

You might see a keyword appear multiple times, because git reads the same keyword from different files (for example:/etc/gitconfig and ~/.gitconfig). In this case, Git uses the last value for each unique keyword.

You can also look at the current value of a particular keyword that git believes to be, using the following command git config {key}:

$ git config user.name

Scott Chacon

2.5 Get Assistance (Getting help)

If you need help with Git, there are three ways to get the manual page (manpage) help for any git command:

$ git help <verb>

$ git <verb>--help

$ mans git-<verb>

For example, you can run the following command to get the manual pages Help for the config command :

$ git help config

to set the color of git status:git config--global color.status auto

Http://www.cnblogs.com/wanqieddy/archive/2012/08/03/2621027.html

Git has two configuration files:

(1) Global, the. gitconfig file in the home directory of the current user. echo%userprofile% can view the current user directory of Windows, Linux at/home/Current user/Next, or use CD to enter
(2) configuration file for a specific git repository:. git/config

GIT uses the HTTPS protocol, each pull, push to enter a password, rather annoying.
Use the GIT protocol, and then use the SSH key. This saves the password every time you lose it.


It takes about three steps:
First, the local generated key pair;
Second, set the public key on GitHub;
Third, modify git's remote URL is the GIT protocol.


First, generate a key pair.
=============
Most Git servers will choose to use the SSH public key for authorization. Each user in the system must provide a public key for authorization, and none will generate one. The process of generating the public key is similar on all operating systems. First make sure you have a public key. The SSH public key is stored by default in the directory under the account's home directory ~/.ssh . Go inside and see:

$ cd ~/.ssh $ lsauthorized_keys2 id_dsa known_hosts config id_dsa.pub

The key is to see if there is something something.pub a pair of files to use and to name, this something is usually id_dsa or id_rsa . .pubthe file with the suffix is the public key, and the other file is the key. If you don't have these files, or simply .ssh don't have a directory, you can ssh-keygen create them. The program is provided by the SSH package on the LINUX/MAC system and is included in the Msysgit package on Windows:

$ ssh-keygen -t RSA -C "[email protected]"

# Creates a new SSH key using the provided email # generating public/private RSA key pair.

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

Just enter the line. Then, you will be prompted to enter the password, as follows (recommended to lose one, a little safer, of course, do not lose):

Enter(forno passphrase):[Type a passphrase]    [Type passphrase again]      

After that, that's probably it.

Your in/home/you/.  SSH/id_rsa.  Your public key have been saved in/home/you/.ssh/id_rsa.pub.  The key fingerprint is:[email protected]            

Such Your local generate key pair work is done.


Second, add the public key to your GitHub account
========================
1. Look at the public key you generated: probably as follows:

$ cat~/.ssh/Id_rsa.PubSsh-RSA Aaaab3nzac1yc2eaaaabiwaaaqeakloupkdhrfhy17sbrmtipnltgk9tjom/BwdsuGpl+Nafzlhdtyw7hdi4yz5ew18jh4jw9jbhufrviqzm7xleLevf4h9lfx5qvkbpppswg0cda3 Pbv7kodj/Mtyblwxfcr+hao3fxritbqxix1nkhxphazsmcilq8v6rjsnaqwdsdmfvslvk/7XA< Span class= "PLN" > T3faojoasncm1q9x5+3v0ww68 /eifmb1zuufljqjkprrx88xypndvjynby6vw/ Pb0rwert/en Mz+/il8b++1nkatmikjn2so1d01qratlmqvssbx  Nrrfi9wrf+m7q== [email protected]< Span class= "pun". local               

2. Log in to your GitHub account. Then on the left column of account Settings, click SSH keys, click Add SSH key
3. Then you copy the above public key content and paste it into the "key" text field. Title field, you can just fill in a line.
4, finished, click Add Key.

That way, it's OK. Then, verify that the key is not working correctly.

-T [email protected].  COM# attempts to ssh to GitHub   

If, see:

Hiusername!  You'vesuccessfully authenticated, but GitHub does notprovide shell access.   

It means that your setup has been successful.


Third, modify your local SSH remote URL. Use the GIT protocol instead of the HTTPS protocol
================================================
You can use Git remote-v to view your current remote URL

$ git remote -v

Origin HTTPS://github.com/someaccount/someproject.git (Fetch)origin HTTPS://github.com/ Someaccount/someproject.git (push)

You can see that it is accessed using the HTTPS protocol.

You can use your browser to log in to your github and see the URL for your SSH protocol. Similar to the following:

[Email protected] . com:someaccount/someproject. git

At this point, you can use Git remote Set-url to adjust your URL.

Git remote set-URL origin [email protected]. COM:someaccount/someproject. git

When you're done, you can use Git remote-v to see it again.

Ok.

At this point, OK.

You can use git fetch, git pull, git push, now remote operation, should not need to enter the password so annoying.

http://blog.csdn.net/wfdtxz/article/details/8678982

git uses SSH keys and HTTPS two authentication methods to summarize (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.