Why do I get a “Connection to [host] closed by remote host” error over SFTP connection?











up vote
2
down vote

favorite
1












I'd like to connect as user to a remote host through SFTP.



Moreover, I'd like to land into a specific directory (say /home/user/dir). I've created user with default working directory as /home/user/dirand set a /home/user/.ssh/authorized_key file to host my public key.



However, upon connexion using sftp -P 7000 user@host.com and after typing user's password, I get the following error immediatly: Connection to host.com closed by remote host. Connection closed.



Any idea about where it might come from (or how to debug that kind of issue)?



UPDATE



I was finally to connect as user because authorized_key didn't have the proper rights. However, I got the exact same error message while trying to land in /home/user/dir with another user (say user2) which was granted group access to /home/user/dir. But as it turn out in this response, SFTP chroot jail does not allow that by design. I'll try to use symbolic links between /home/user/dir and /home/user2/dir to solve this issue.










share|improve this question




















  • 1




    First add -vvv: sftp -P 7000 user@host.com -vvv and show output
    – Tomasz Jakub Rup
    Nov 9 at 14:24










  • I get the exact same output : Connection to host.com closed by remote host. Connection closed.
    – Crolle
    Nov 9 at 14:44










  • Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
    – hyph
    Nov 9 at 14:52












  • Sorry, my fault: sftp -P 7000 -vvv user@host.com
    – Tomasz Jakub Rup
    Nov 9 at 14:59










  • @hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
    – Crolle
    Nov 9 at 15:42















up vote
2
down vote

favorite
1












I'd like to connect as user to a remote host through SFTP.



Moreover, I'd like to land into a specific directory (say /home/user/dir). I've created user with default working directory as /home/user/dirand set a /home/user/.ssh/authorized_key file to host my public key.



However, upon connexion using sftp -P 7000 user@host.com and after typing user's password, I get the following error immediatly: Connection to host.com closed by remote host. Connection closed.



Any idea about where it might come from (or how to debug that kind of issue)?



UPDATE



I was finally to connect as user because authorized_key didn't have the proper rights. However, I got the exact same error message while trying to land in /home/user/dir with another user (say user2) which was granted group access to /home/user/dir. But as it turn out in this response, SFTP chroot jail does not allow that by design. I'll try to use symbolic links between /home/user/dir and /home/user2/dir to solve this issue.










share|improve this question




















  • 1




    First add -vvv: sftp -P 7000 user@host.com -vvv and show output
    – Tomasz Jakub Rup
    Nov 9 at 14:24










  • I get the exact same output : Connection to host.com closed by remote host. Connection closed.
    – Crolle
    Nov 9 at 14:44










  • Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
    – hyph
    Nov 9 at 14:52












  • Sorry, my fault: sftp -P 7000 -vvv user@host.com
    – Tomasz Jakub Rup
    Nov 9 at 14:59










  • @hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
    – Crolle
    Nov 9 at 15:42













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I'd like to connect as user to a remote host through SFTP.



Moreover, I'd like to land into a specific directory (say /home/user/dir). I've created user with default working directory as /home/user/dirand set a /home/user/.ssh/authorized_key file to host my public key.



However, upon connexion using sftp -P 7000 user@host.com and after typing user's password, I get the following error immediatly: Connection to host.com closed by remote host. Connection closed.



Any idea about where it might come from (or how to debug that kind of issue)?



UPDATE



I was finally to connect as user because authorized_key didn't have the proper rights. However, I got the exact same error message while trying to land in /home/user/dir with another user (say user2) which was granted group access to /home/user/dir. But as it turn out in this response, SFTP chroot jail does not allow that by design. I'll try to use symbolic links between /home/user/dir and /home/user2/dir to solve this issue.










share|improve this question















I'd like to connect as user to a remote host through SFTP.



Moreover, I'd like to land into a specific directory (say /home/user/dir). I've created user with default working directory as /home/user/dirand set a /home/user/.ssh/authorized_key file to host my public key.



However, upon connexion using sftp -P 7000 user@host.com and after typing user's password, I get the following error immediatly: Connection to host.com closed by remote host. Connection closed.



Any idea about where it might come from (or how to debug that kind of issue)?



UPDATE



I was finally to connect as user because authorized_key didn't have the proper rights. However, I got the exact same error message while trying to land in /home/user/dir with another user (say user2) which was granted group access to /home/user/dir. But as it turn out in this response, SFTP chroot jail does not allow that by design. I'll try to use symbolic links between /home/user/dir and /home/user2/dir to solve this issue.







linux ssh sftp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 11:13

























asked Nov 9 at 13:08









Crolle

1112




1112








  • 1




    First add -vvv: sftp -P 7000 user@host.com -vvv and show output
    – Tomasz Jakub Rup
    Nov 9 at 14:24










  • I get the exact same output : Connection to host.com closed by remote host. Connection closed.
    – Crolle
    Nov 9 at 14:44










  • Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
    – hyph
    Nov 9 at 14:52












  • Sorry, my fault: sftp -P 7000 -vvv user@host.com
    – Tomasz Jakub Rup
    Nov 9 at 14:59










  • @hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
    – Crolle
    Nov 9 at 15:42














  • 1




    First add -vvv: sftp -P 7000 user@host.com -vvv and show output
    – Tomasz Jakub Rup
    Nov 9 at 14:24










  • I get the exact same output : Connection to host.com closed by remote host. Connection closed.
    – Crolle
    Nov 9 at 14:44










  • Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
    – hyph
    Nov 9 at 14:52












  • Sorry, my fault: sftp -P 7000 -vvv user@host.com
    – Tomasz Jakub Rup
    Nov 9 at 14:59










  • @hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
    – Crolle
    Nov 9 at 15:42








1




1




First add -vvv: sftp -P 7000 user@host.com -vvv and show output
– Tomasz Jakub Rup
Nov 9 at 14:24




First add -vvv: sftp -P 7000 user@host.com -vvv and show output
– Tomasz Jakub Rup
Nov 9 at 14:24












I get the exact same output : Connection to host.com closed by remote host. Connection closed.
– Crolle
Nov 9 at 14:44




I get the exact same output : Connection to host.com closed by remote host. Connection closed.
– Crolle
Nov 9 at 14:44












Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
– hyph
Nov 9 at 14:52






Did you set /home/user/dir as your user's $HOME ? or what else did you do to "land into a specific directory" ? Did logging in work before you changed that directory?
– hyph
Nov 9 at 14:52














Sorry, my fault: sftp -P 7000 -vvv user@host.com
– Tomasz Jakub Rup
Nov 9 at 14:59




Sorry, my fault: sftp -P 7000 -vvv user@host.com
– Tomasz Jakub Rup
Nov 9 at 14:59












@hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
– Crolle
Nov 9 at 15:42




@hyph I defined user default directory using usermod -m -d /home/user/dir user @Tomasz Jakub Rup The log is quite extensive : pastebin.com/0dRZBPUS
– Crolle
Nov 9 at 15:42










1 Answer
1






active

oldest

votes

















up vote
1
down vote













How to debug



First step is running command with verbose flag:



sftp -P 7000 -vvv user@host.com


Analyze of log



Connection are estabilished



debug1: Authentication succeeded (publickey).


but, ssh cannot set non-blocking mode:



debug3: fd 1 is not O_NONBLOCK
Connection to host.com closed by remote host.


Probably Your shell initialization file (.bashrc, .bash_profile, etc.) breaking ssh connection






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    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',
    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%2fsuperuser.com%2fquestions%2f1374078%2fwhy-do-i-get-a-connection-to-host-closed-by-remote-host-error-over-sftp-conn%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








    up vote
    1
    down vote













    How to debug



    First step is running command with verbose flag:



    sftp -P 7000 -vvv user@host.com


    Analyze of log



    Connection are estabilished



    debug1: Authentication succeeded (publickey).


    but, ssh cannot set non-blocking mode:



    debug3: fd 1 is not O_NONBLOCK
    Connection to host.com closed by remote host.


    Probably Your shell initialization file (.bashrc, .bash_profile, etc.) breaking ssh connection






    share|improve this answer

























      up vote
      1
      down vote













      How to debug



      First step is running command with verbose flag:



      sftp -P 7000 -vvv user@host.com


      Analyze of log



      Connection are estabilished



      debug1: Authentication succeeded (publickey).


      but, ssh cannot set non-blocking mode:



      debug3: fd 1 is not O_NONBLOCK
      Connection to host.com closed by remote host.


      Probably Your shell initialization file (.bashrc, .bash_profile, etc.) breaking ssh connection






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        How to debug



        First step is running command with verbose flag:



        sftp -P 7000 -vvv user@host.com


        Analyze of log



        Connection are estabilished



        debug1: Authentication succeeded (publickey).


        but, ssh cannot set non-blocking mode:



        debug3: fd 1 is not O_NONBLOCK
        Connection to host.com closed by remote host.


        Probably Your shell initialization file (.bashrc, .bash_profile, etc.) breaking ssh connection






        share|improve this answer












        How to debug



        First step is running command with verbose flag:



        sftp -P 7000 -vvv user@host.com


        Analyze of log



        Connection are estabilished



        debug1: Authentication succeeded (publickey).


        but, ssh cannot set non-blocking mode:



        debug3: fd 1 is not O_NONBLOCK
        Connection to host.com closed by remote host.


        Probably Your shell initialization file (.bashrc, .bash_profile, etc.) breaking ssh connection







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 20:04









        Tomasz Jakub Rup

        560313




        560313






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1374078%2fwhy-do-i-get-a-connection-to-host-closed-by-remote-host-error-over-sftp-conn%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

            Сан-Квентин

            Алькесар

            Josef Freinademetz