How do I avoid the specification of the username and password at every git push?

前端 未结 18 1780
我在风中等你
我在风中等你 2020-11-28 00:02

I git push my work to a remote Git repository.

Every push will prompt me to input username and password. I would

18条回答
  •  悲&欢浪女
    2020-11-28 00:35

    As far as I know, there are simply two safe ways: ssh or passwd encrypted using a keystore.

    SSH

    1. Log in your github;
    2. Visit: https://github.com/settings/keys;
    3. New SSH key;
    4. cat ~/.ssh/id_rsa.pub, paste it there, name and save it (if you have no such file, generate one for yourself by ssh-keygen -t rsa - just Enter for all prompts);
    5. Go to your local repository and update your remote by git remote set-url origin git+ssh://git@github.com/username/reponame.git - you can check it first by git remote -v);
    6. Here you go, just touch t; git add t; git commit -m "test"; git push and confirm yes to enjoy the password-free world.

    passwd ENCRYPTED using a keystore

    If you just use git config --global credential.helper store as others mentioned, your unencrypted passwords will be just stored in a plain text under ~/.git-credentials which is not safe as it sounds.

    Try to encrypt it as

    sudo apt-get install libgnome-keyring-dev
    sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring
    git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
    
    git config --global credential.helper store
    

    In this case, you are using https://git@github.com/username/reponame.git.

提交回复
热议问题