Search code examples
gitraspberry-pigit-shell

Secure push and pull with no password GIT


I am working on my raspberry pi server and whenever I clone or do anything on the gitremotely I want to disable password on the push and pull. How do I do that? I don't want to enter password on git shell when I try to pull or push any changes to the server.


Solution

  • You need to generate your SSH keys (like @Ajedi32 exlains) or like is explained on github page : https://help.github.com/articles/generating-ssh-keys

    Also currently if you type git remote -v you will see that your repository (origin probably) will have pathes starting with https://github.com/user/repo.git). This means that git on your local machine is referring to remote git repo via https. When referring to the remote git repo via https, git will ALWAYS ask for password.

    This is why AFTER you have set up the SSH keys as described in one of the methods above, you must change the way git is referring to the remote repo from https protocol to ssh protocol.

    To do that you first have to write down you current repo path, eg. https://github.com/username/reponame.git then you can convert it to the ssh style address: ssh://[email protected]/username/reponame.git (mind that you only have to change username and reponame parts. Leave [email protected] as it is. It always must be like this.

    Then on your local machine you can type the following code: If you're on linux

    git remote -v
    git remote rm origin
    git remote add origin ssh://[email protected]/username/reponame.git
    git remote -v 
    

    The last command will print you the path via which git refers to the remote repository and it will be starting with ssh://....

    Mind that when using command git remote -v the repository path will be printed twice, once for fetch and once with push comment.