How do I setup SSH key based authentication for GitHub by using ~/.ssh/config file?












1















I am trying to set up my SSH keys for GitHub and created a new SSH key for the same. I have managed to setup the SSH key but I wish to retain these settings and save them in the configuration file ~/.ssh/config which is not available. Where can I add this key path to retain the configuration?










share|improve this question





























    1















    I am trying to set up my SSH keys for GitHub and created a new SSH key for the same. I have managed to setup the SSH key but I wish to retain these settings and save them in the configuration file ~/.ssh/config which is not available. Where can I add this key path to retain the configuration?










    share|improve this question



























      1












      1








      1








      I am trying to set up my SSH keys for GitHub and created a new SSH key for the same. I have managed to setup the SSH key but I wish to retain these settings and save them in the configuration file ~/.ssh/config which is not available. Where can I add this key path to retain the configuration?










      share|improve this question
















      I am trying to set up my SSH keys for GitHub and created a new SSH key for the same. I have managed to setup the SSH key but I wish to retain these settings and save them in the configuration file ~/.ssh/config which is not available. Where can I add this key path to retain the configuration?







      ssh git openssh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 29 '18 at 11:11









      pa4080

      13.6k52564




      13.6k52564










      asked Nov 29 '18 at 7:57









      Sushant KumarSushant Kumar

      83




      83






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Here is short manual how to setup SSH key based authentication for GitHub.



          1. Install the openssh-client if it is not already installed, and of course git:



          sudo apt update && sudo apt install -y openssh-client git


          2. Create user's ssh directory and a sub directory where your dedicated GitHub ssh key will be stored:



          mkdir -p ~/.ssh/github
          chmod 700 ~/.ssh ~/.ssh/github


          3. Generate the SSH key (the output key will have octal permissions 600):



          ssh-keygen -t rsa -b 4096 -C 'your@email.com' -f ~/.ssh/github/id_rsa -q -N ''




          • -q - silence ssh-keygen; -N '' - empty (without) passphrase, you can assign one if you want.


          4. Copy the content of the file id_rsa.pub, use the following command to output it:



          cat ~/.ssh/github/id_rsa.pub


          5. Go to your GitHub account. From the drop-down menu in upper right corner select Your profile. Click on Edit profile button and then select SSH and GPG keys. Click on the New SSH Key button. Type some meningful for a Title and paste the content of ~/.ssh/github/id_rsa.pub in the field Key. Then click on the Add SSH Key button.



          enter image description here



          6. Create the ~/.ssh/config file, if it doesn't already exist:



          touch ~/.ssh/config
          chmod 600 ~/.ssh/config


          Edit the config file and add the following entry for the new SSH key:



          Host github.com
          IdentityFile ~/.ssh/github/id_rsa


          7. Test the setup. Use the following command:



          ssh -T git@github.com


          On the question - Are you sure you want to continue connecting (yes/no)? - answer with yes. If everything went well you should receive a greeting message like this:



          Hi pa4080! You've successfully authenticated, ...




          How to use the SSH key.



          1. If you have already cloned repository through HTTPS, by using a command as these:



          git clone https://github.com/username/repository-name.git
          git clone git://github.com/username/repository-name


          Go inside the repository's directory and execute the next command to allow work via SSH:



          git remote set-url origin git@github.com:username/repository-name.git


          2. Direct clone a repository via SSH:



          git clone git@github.com:username/repository-name.git


          3. In addition if you are using VSC it will work without problems with this setup. For already clonned repositories just use the Open Folder option and all VSC Git features will work.






          share|improve this answer

































            1














            this file is not available by default. You have to create it.
            Please be aware SSH keys and ~/.ssh/config are separate files (with different purpose).



            your SSH keys are stored in ~/.ssh (use ls -al ~/.ssh to see them all)
            and your SSH config is stored in the ~/.ssh/config. If you don't have it feel free to use touch ~/.ssh/config to create it.



            If you want to use your key with github/bitbucket/gitlab use the following:



            eval `ssh-agent`
            ssh-add ~/.ssh/id_rsa


            in the above case id_rsa is your private SSH key file, just change it to your real private key file name






            share|improve this answer


























            • There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

              – Underverse
              Nov 29 '18 at 11:07











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1097038%2fhow-do-i-setup-ssh-key-based-authentication-for-github-by-using-ssh-config-fi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Here is short manual how to setup SSH key based authentication for GitHub.



            1. Install the openssh-client if it is not already installed, and of course git:



            sudo apt update && sudo apt install -y openssh-client git


            2. Create user's ssh directory and a sub directory where your dedicated GitHub ssh key will be stored:



            mkdir -p ~/.ssh/github
            chmod 700 ~/.ssh ~/.ssh/github


            3. Generate the SSH key (the output key will have octal permissions 600):



            ssh-keygen -t rsa -b 4096 -C 'your@email.com' -f ~/.ssh/github/id_rsa -q -N ''




            • -q - silence ssh-keygen; -N '' - empty (without) passphrase, you can assign one if you want.


            4. Copy the content of the file id_rsa.pub, use the following command to output it:



            cat ~/.ssh/github/id_rsa.pub


            5. Go to your GitHub account. From the drop-down menu in upper right corner select Your profile. Click on Edit profile button and then select SSH and GPG keys. Click on the New SSH Key button. Type some meningful for a Title and paste the content of ~/.ssh/github/id_rsa.pub in the field Key. Then click on the Add SSH Key button.



            enter image description here



            6. Create the ~/.ssh/config file, if it doesn't already exist:



            touch ~/.ssh/config
            chmod 600 ~/.ssh/config


            Edit the config file and add the following entry for the new SSH key:



            Host github.com
            IdentityFile ~/.ssh/github/id_rsa


            7. Test the setup. Use the following command:



            ssh -T git@github.com


            On the question - Are you sure you want to continue connecting (yes/no)? - answer with yes. If everything went well you should receive a greeting message like this:



            Hi pa4080! You've successfully authenticated, ...




            How to use the SSH key.



            1. If you have already cloned repository through HTTPS, by using a command as these:



            git clone https://github.com/username/repository-name.git
            git clone git://github.com/username/repository-name


            Go inside the repository's directory and execute the next command to allow work via SSH:



            git remote set-url origin git@github.com:username/repository-name.git


            2. Direct clone a repository via SSH:



            git clone git@github.com:username/repository-name.git


            3. In addition if you are using VSC it will work without problems with this setup. For already clonned repositories just use the Open Folder option and all VSC Git features will work.






            share|improve this answer






























              2














              Here is short manual how to setup SSH key based authentication for GitHub.



              1. Install the openssh-client if it is not already installed, and of course git:



              sudo apt update && sudo apt install -y openssh-client git


              2. Create user's ssh directory and a sub directory where your dedicated GitHub ssh key will be stored:



              mkdir -p ~/.ssh/github
              chmod 700 ~/.ssh ~/.ssh/github


              3. Generate the SSH key (the output key will have octal permissions 600):



              ssh-keygen -t rsa -b 4096 -C 'your@email.com' -f ~/.ssh/github/id_rsa -q -N ''




              • -q - silence ssh-keygen; -N '' - empty (without) passphrase, you can assign one if you want.


              4. Copy the content of the file id_rsa.pub, use the following command to output it:



              cat ~/.ssh/github/id_rsa.pub


              5. Go to your GitHub account. From the drop-down menu in upper right corner select Your profile. Click on Edit profile button and then select SSH and GPG keys. Click on the New SSH Key button. Type some meningful for a Title and paste the content of ~/.ssh/github/id_rsa.pub in the field Key. Then click on the Add SSH Key button.



              enter image description here



              6. Create the ~/.ssh/config file, if it doesn't already exist:



              touch ~/.ssh/config
              chmod 600 ~/.ssh/config


              Edit the config file and add the following entry for the new SSH key:



              Host github.com
              IdentityFile ~/.ssh/github/id_rsa


              7. Test the setup. Use the following command:



              ssh -T git@github.com


              On the question - Are you sure you want to continue connecting (yes/no)? - answer with yes. If everything went well you should receive a greeting message like this:



              Hi pa4080! You've successfully authenticated, ...




              How to use the SSH key.



              1. If you have already cloned repository through HTTPS, by using a command as these:



              git clone https://github.com/username/repository-name.git
              git clone git://github.com/username/repository-name


              Go inside the repository's directory and execute the next command to allow work via SSH:



              git remote set-url origin git@github.com:username/repository-name.git


              2. Direct clone a repository via SSH:



              git clone git@github.com:username/repository-name.git


              3. In addition if you are using VSC it will work without problems with this setup. For already clonned repositories just use the Open Folder option and all VSC Git features will work.






              share|improve this answer




























                2












                2








                2







                Here is short manual how to setup SSH key based authentication for GitHub.



                1. Install the openssh-client if it is not already installed, and of course git:



                sudo apt update && sudo apt install -y openssh-client git


                2. Create user's ssh directory and a sub directory where your dedicated GitHub ssh key will be stored:



                mkdir -p ~/.ssh/github
                chmod 700 ~/.ssh ~/.ssh/github


                3. Generate the SSH key (the output key will have octal permissions 600):



                ssh-keygen -t rsa -b 4096 -C 'your@email.com' -f ~/.ssh/github/id_rsa -q -N ''




                • -q - silence ssh-keygen; -N '' - empty (without) passphrase, you can assign one if you want.


                4. Copy the content of the file id_rsa.pub, use the following command to output it:



                cat ~/.ssh/github/id_rsa.pub


                5. Go to your GitHub account. From the drop-down menu in upper right corner select Your profile. Click on Edit profile button and then select SSH and GPG keys. Click on the New SSH Key button. Type some meningful for a Title and paste the content of ~/.ssh/github/id_rsa.pub in the field Key. Then click on the Add SSH Key button.



                enter image description here



                6. Create the ~/.ssh/config file, if it doesn't already exist:



                touch ~/.ssh/config
                chmod 600 ~/.ssh/config


                Edit the config file and add the following entry for the new SSH key:



                Host github.com
                IdentityFile ~/.ssh/github/id_rsa


                7. Test the setup. Use the following command:



                ssh -T git@github.com


                On the question - Are you sure you want to continue connecting (yes/no)? - answer with yes. If everything went well you should receive a greeting message like this:



                Hi pa4080! You've successfully authenticated, ...




                How to use the SSH key.



                1. If you have already cloned repository through HTTPS, by using a command as these:



                git clone https://github.com/username/repository-name.git
                git clone git://github.com/username/repository-name


                Go inside the repository's directory and execute the next command to allow work via SSH:



                git remote set-url origin git@github.com:username/repository-name.git


                2. Direct clone a repository via SSH:



                git clone git@github.com:username/repository-name.git


                3. In addition if you are using VSC it will work without problems with this setup. For already clonned repositories just use the Open Folder option and all VSC Git features will work.






                share|improve this answer















                Here is short manual how to setup SSH key based authentication for GitHub.



                1. Install the openssh-client if it is not already installed, and of course git:



                sudo apt update && sudo apt install -y openssh-client git


                2. Create user's ssh directory and a sub directory where your dedicated GitHub ssh key will be stored:



                mkdir -p ~/.ssh/github
                chmod 700 ~/.ssh ~/.ssh/github


                3. Generate the SSH key (the output key will have octal permissions 600):



                ssh-keygen -t rsa -b 4096 -C 'your@email.com' -f ~/.ssh/github/id_rsa -q -N ''




                • -q - silence ssh-keygen; -N '' - empty (without) passphrase, you can assign one if you want.


                4. Copy the content of the file id_rsa.pub, use the following command to output it:



                cat ~/.ssh/github/id_rsa.pub


                5. Go to your GitHub account. From the drop-down menu in upper right corner select Your profile. Click on Edit profile button and then select SSH and GPG keys. Click on the New SSH Key button. Type some meningful for a Title and paste the content of ~/.ssh/github/id_rsa.pub in the field Key. Then click on the Add SSH Key button.



                enter image description here



                6. Create the ~/.ssh/config file, if it doesn't already exist:



                touch ~/.ssh/config
                chmod 600 ~/.ssh/config


                Edit the config file and add the following entry for the new SSH key:



                Host github.com
                IdentityFile ~/.ssh/github/id_rsa


                7. Test the setup. Use the following command:



                ssh -T git@github.com


                On the question - Are you sure you want to continue connecting (yes/no)? - answer with yes. If everything went well you should receive a greeting message like this:



                Hi pa4080! You've successfully authenticated, ...




                How to use the SSH key.



                1. If you have already cloned repository through HTTPS, by using a command as these:



                git clone https://github.com/username/repository-name.git
                git clone git://github.com/username/repository-name


                Go inside the repository's directory and execute the next command to allow work via SSH:



                git remote set-url origin git@github.com:username/repository-name.git


                2. Direct clone a repository via SSH:



                git clone git@github.com:username/repository-name.git


                3. In addition if you are using VSC it will work without problems with this setup. For already clonned repositories just use the Open Folder option and all VSC Git features will work.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 10 hours ago

























                answered Nov 29 '18 at 10:54









                pa4080pa4080

                13.6k52564




                13.6k52564

























                    1














                    this file is not available by default. You have to create it.
                    Please be aware SSH keys and ~/.ssh/config are separate files (with different purpose).



                    your SSH keys are stored in ~/.ssh (use ls -al ~/.ssh to see them all)
                    and your SSH config is stored in the ~/.ssh/config. If you don't have it feel free to use touch ~/.ssh/config to create it.



                    If you want to use your key with github/bitbucket/gitlab use the following:



                    eval `ssh-agent`
                    ssh-add ~/.ssh/id_rsa


                    in the above case id_rsa is your private SSH key file, just change it to your real private key file name






                    share|improve this answer


























                    • There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                      – Underverse
                      Nov 29 '18 at 11:07
















                    1














                    this file is not available by default. You have to create it.
                    Please be aware SSH keys and ~/.ssh/config are separate files (with different purpose).



                    your SSH keys are stored in ~/.ssh (use ls -al ~/.ssh to see them all)
                    and your SSH config is stored in the ~/.ssh/config. If you don't have it feel free to use touch ~/.ssh/config to create it.



                    If you want to use your key with github/bitbucket/gitlab use the following:



                    eval `ssh-agent`
                    ssh-add ~/.ssh/id_rsa


                    in the above case id_rsa is your private SSH key file, just change it to your real private key file name






                    share|improve this answer


























                    • There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                      – Underverse
                      Nov 29 '18 at 11:07














                    1












                    1








                    1







                    this file is not available by default. You have to create it.
                    Please be aware SSH keys and ~/.ssh/config are separate files (with different purpose).



                    your SSH keys are stored in ~/.ssh (use ls -al ~/.ssh to see them all)
                    and your SSH config is stored in the ~/.ssh/config. If you don't have it feel free to use touch ~/.ssh/config to create it.



                    If you want to use your key with github/bitbucket/gitlab use the following:



                    eval `ssh-agent`
                    ssh-add ~/.ssh/id_rsa


                    in the above case id_rsa is your private SSH key file, just change it to your real private key file name






                    share|improve this answer















                    this file is not available by default. You have to create it.
                    Please be aware SSH keys and ~/.ssh/config are separate files (with different purpose).



                    your SSH keys are stored in ~/.ssh (use ls -al ~/.ssh to see them all)
                    and your SSH config is stored in the ~/.ssh/config. If you don't have it feel free to use touch ~/.ssh/config to create it.



                    If you want to use your key with github/bitbucket/gitlab use the following:



                    eval `ssh-agent`
                    ssh-add ~/.ssh/id_rsa


                    in the above case id_rsa is your private SSH key file, just change it to your real private key file name







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 29 '18 at 11:13









                    pa4080

                    13.6k52564




                    13.6k52564










                    answered Nov 29 '18 at 8:13









                    janmyszkierjanmyszkier

                    52127




                    52127













                    • There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                      – Underverse
                      Nov 29 '18 at 11:07



















                    • There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                      – Underverse
                      Nov 29 '18 at 11:07

















                    There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                    – Underverse
                    Nov 29 '18 at 11:07





                    There is a strange problem where if the ~/.ssh/config file doesn't exist then the configuration settings don't set. Best to always create it if it doesn't exist.

                    – Underverse
                    Nov 29 '18 at 11:07


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1097038%2fhow-do-i-setup-ssh-key-based-authentication-for-github-by-using-ssh-config-fi%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    GameSpot

                    日野市

                    Tu-95轟炸機