Cannot connect with private key if the public key exists












0















I'm trying to connect with a specific key on a server but for some reason I cannot connect with my private key if the public key exists next to it.
Both clients and servers are Ubuntu 16.04.



The current situation: I have my ssh keys in my .ssh folder:



samk@local:~$ ls -ld .ssh
drwx------ 2 samk samk 4096 Oct 29 11:36 .ssh
samk@local:~$ ls -l .ssh/jenkins-slave*
-rw------- 1 samk samk 1679 Oct 24 13:23 .ssh/jenkins-slave_rsa
-rw------- 1 samk samk 429 Oct 24 12:09 .ssh/jenkins-slave_rsa.pub


The problem is I cannot connect using my ssh private key:



samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01
Permission denied (publickey).


If I rename the public key to something else, I can connect:



samk@local:~$ mv .ssh/jenkins-slave_rsa.pub .ssh/jenkins-slave_other
samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-137-generic x86_64)
Last login: Mon Oct 29 10:25:32 2018 from 192.168.0.88

ubuntu@jenkins-slave-01:~$


If I rename back the public key, I cannot connect anymore.



What is happening here?










share|improve this question




















  • 2





    You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

    – Lewis M
    Oct 29 '18 at 12:32











  • Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

    – SamK
    Oct 29 '18 at 13:30











  • The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

    – SamK
    Oct 29 '18 at 14:42











  • try chmod 644 .ssh/jenkins-slave_rsa.pub

    – Alvin Liang
    Oct 29 '18 at 21:28
















0















I'm trying to connect with a specific key on a server but for some reason I cannot connect with my private key if the public key exists next to it.
Both clients and servers are Ubuntu 16.04.



The current situation: I have my ssh keys in my .ssh folder:



samk@local:~$ ls -ld .ssh
drwx------ 2 samk samk 4096 Oct 29 11:36 .ssh
samk@local:~$ ls -l .ssh/jenkins-slave*
-rw------- 1 samk samk 1679 Oct 24 13:23 .ssh/jenkins-slave_rsa
-rw------- 1 samk samk 429 Oct 24 12:09 .ssh/jenkins-slave_rsa.pub


The problem is I cannot connect using my ssh private key:



samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01
Permission denied (publickey).


If I rename the public key to something else, I can connect:



samk@local:~$ mv .ssh/jenkins-slave_rsa.pub .ssh/jenkins-slave_other
samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-137-generic x86_64)
Last login: Mon Oct 29 10:25:32 2018 from 192.168.0.88

ubuntu@jenkins-slave-01:~$


If I rename back the public key, I cannot connect anymore.



What is happening here?










share|improve this question




















  • 2





    You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

    – Lewis M
    Oct 29 '18 at 12:32











  • Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

    – SamK
    Oct 29 '18 at 13:30











  • The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

    – SamK
    Oct 29 '18 at 14:42











  • try chmod 644 .ssh/jenkins-slave_rsa.pub

    – Alvin Liang
    Oct 29 '18 at 21:28














0












0








0








I'm trying to connect with a specific key on a server but for some reason I cannot connect with my private key if the public key exists next to it.
Both clients and servers are Ubuntu 16.04.



The current situation: I have my ssh keys in my .ssh folder:



samk@local:~$ ls -ld .ssh
drwx------ 2 samk samk 4096 Oct 29 11:36 .ssh
samk@local:~$ ls -l .ssh/jenkins-slave*
-rw------- 1 samk samk 1679 Oct 24 13:23 .ssh/jenkins-slave_rsa
-rw------- 1 samk samk 429 Oct 24 12:09 .ssh/jenkins-slave_rsa.pub


The problem is I cannot connect using my ssh private key:



samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01
Permission denied (publickey).


If I rename the public key to something else, I can connect:



samk@local:~$ mv .ssh/jenkins-slave_rsa.pub .ssh/jenkins-slave_other
samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-137-generic x86_64)
Last login: Mon Oct 29 10:25:32 2018 from 192.168.0.88

ubuntu@jenkins-slave-01:~$


If I rename back the public key, I cannot connect anymore.



What is happening here?










share|improve this question
















I'm trying to connect with a specific key on a server but for some reason I cannot connect with my private key if the public key exists next to it.
Both clients and servers are Ubuntu 16.04.



The current situation: I have my ssh keys in my .ssh folder:



samk@local:~$ ls -ld .ssh
drwx------ 2 samk samk 4096 Oct 29 11:36 .ssh
samk@local:~$ ls -l .ssh/jenkins-slave*
-rw------- 1 samk samk 1679 Oct 24 13:23 .ssh/jenkins-slave_rsa
-rw------- 1 samk samk 429 Oct 24 12:09 .ssh/jenkins-slave_rsa.pub


The problem is I cannot connect using my ssh private key:



samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01
Permission denied (publickey).


If I rename the public key to something else, I can connect:



samk@local:~$ mv .ssh/jenkins-slave_rsa.pub .ssh/jenkins-slave_other
samk@local:~$ /usr/bin/ssh -i ~/.ssh/jenkins-slave_rsa ubuntu@jenkins-slave-01

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-137-generic x86_64)
Last login: Mon Oct 29 10:25:32 2018 from 192.168.0.88

ubuntu@jenkins-slave-01:~$


If I rename back the public key, I cannot connect anymore.



What is happening here?







server ssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 29 '18 at 13:31







SamK

















asked Oct 29 '18 at 11:03









SamKSamK

1614




1614








  • 2





    You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

    – Lewis M
    Oct 29 '18 at 12:32











  • Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

    – SamK
    Oct 29 '18 at 13:30











  • The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

    – SamK
    Oct 29 '18 at 14:42











  • try chmod 644 .ssh/jenkins-slave_rsa.pub

    – Alvin Liang
    Oct 29 '18 at 21:28














  • 2





    You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

    – Lewis M
    Oct 29 '18 at 12:32











  • Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

    – SamK
    Oct 29 '18 at 13:30











  • The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

    – SamK
    Oct 29 '18 at 14:42











  • try chmod 644 .ssh/jenkins-slave_rsa.pub

    – Alvin Liang
    Oct 29 '18 at 21:28








2




2





You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

– Lewis M
Oct 29 '18 at 12:32





You appear to be going to 2 different hosts, jenkins-slave-01 in the first one (failed one), and jenkins-slave in the second one (good one). Also, you are invoking /usr/bin/ssh in the first one, and just ssh in the second one. Make sure you are running /usr/bin/ssh in both, and going to the same host in both. Also, if you want to ssh into a server without using a password, just the public key, the public key needs to be added into the remote users authorized_keys file. The best way to do that is to run ssh-copy-id. Hope this helps.

– Lewis M
Oct 29 '18 at 12:32













Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

– SamK
Oct 29 '18 at 13:30





Hey Lewis, thank you for your response, that was just a typo, sorry about that. This is indeed the same host. I will correct my post.

– SamK
Oct 29 '18 at 13:30













The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

– SamK
Oct 29 '18 at 14:42





The public key hosted locally happened to be the wrong one. Even if the file was wrong, I don't understand why ssh would refuse the connection.

– SamK
Oct 29 '18 at 14:42













try chmod 644 .ssh/jenkins-slave_rsa.pub

– Alvin Liang
Oct 29 '18 at 21:28





try chmod 644 .ssh/jenkins-slave_rsa.pub

– Alvin Liang
Oct 29 '18 at 21:28










1 Answer
1






active

oldest

votes


















0














It happened that the public key (.ssh/jenkins-slave_rsa.pub) was not matching with the private key (.ssh/jenkins-slave_rsa.pub).



I discovered this while following the steps in this answer: https://serverfault.com/a/426429/30128






share|improve this answer























    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%2f1088228%2fcannot-connect-with-private-key-if-the-public-key-exists%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It happened that the public key (.ssh/jenkins-slave_rsa.pub) was not matching with the private key (.ssh/jenkins-slave_rsa.pub).



    I discovered this while following the steps in this answer: https://serverfault.com/a/426429/30128






    share|improve this answer




























      0














      It happened that the public key (.ssh/jenkins-slave_rsa.pub) was not matching with the private key (.ssh/jenkins-slave_rsa.pub).



      I discovered this while following the steps in this answer: https://serverfault.com/a/426429/30128






      share|improve this answer


























        0












        0








        0







        It happened that the public key (.ssh/jenkins-slave_rsa.pub) was not matching with the private key (.ssh/jenkins-slave_rsa.pub).



        I discovered this while following the steps in this answer: https://serverfault.com/a/426429/30128






        share|improve this answer













        It happened that the public key (.ssh/jenkins-slave_rsa.pub) was not matching with the private key (.ssh/jenkins-slave_rsa.pub).



        I discovered this while following the steps in this answer: https://serverfault.com/a/426429/30128







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 31 at 10:11









        SamKSamK

        1614




        1614






























            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%2f1088228%2fcannot-connect-with-private-key-if-the-public-key-exists%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

            Human spaceflight

            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

            File:DeusFollowingSea.jpg