Skip typing username and password on git push/pull commands

前端 未结 1 1419
-上瘾入骨i
-上瘾入骨i 2021-01-17 02:42

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?

相关标签:
1条回答
  • 2021-01-17 03:22

    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:

    • Local-Protocol

    • The-HTTP-Protocols

    • The-SSH-Protocol

    • The-Git-Protocol


    How to set up ssh key under your GitHub account?

    • Login to GitHub account
    • Click on the rancher on the top right (Settings)
    • Click on the SSH keys and GPG Keys
    • Click on the New SSH key
    • 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.

    0 讨论(0)
提交回复
热议问题