Skip typing username and password on git push/pull

2019-02-20 20:50发布

Anyone know how to set it up so when I'm in the command line and when I push/pull to/from a git repository I don't have to type in my username and password?

Thanks.

1条回答
迷人小祖宗
2楼-- · 2019-02-20 21:23

When you use http/https as your transfer protocol you will be asked for username & password every time.

Switch to ssh key and you will not be asked anymore.

The sample below is how to set the key for GitHub, but i will be same for most of the servers with a minor changes (GUI).

The process is still the same

  • Generate ssh-key
  • Add the key to the server
  • Change the protocol to ssh (git://)

Here is how to set it up:

  • Generate a new ssh key (or skip this step if you already have a key as you mentioned )
    ssh-keygen -t rsa -C "your@email"

  • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the content to the relevant section (ssh keys) under your central repository.


For more information about the transport protocols read this:


How to set up ssh key under your GitHub account?

  • Login to GitHub account
  • Click on the rancher on the top right (Settings)
    enter image description here
  • Click on the SSH keys and GPG Keys
    enter image description here
  • Click on the New SSH key
    enter image description here
  • Paste your key and save

Now it should work


Note

After the first set up open terminal and run a git fetch so the key will be tested and added to your known hosts file.

查看更多
登录 后发表回答