The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error in sshd_config and cannot edit file

Discussion in 'General Discussion' started by MrL22, Jul 26, 2004.

  1. MrL22

    MrL22 Active Member

    Joined:
    Jul 11, 2003
    Messages:
    34
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Tamworth, United Kingdom
    Hi im having same problem as this guy...

    http://forums.cpanel.net/showthread.php?t=11673

    There is an error in sshd_config and sshd will not run, therefor i cannot ssh as root to edit the file to fix the problem...

    all i need is a way to either chmod sshd_config so another user on the server can temporarily edit it or a way to edit the file within root account.

    Any help would be much appreciated! :cool:
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Here's what you can do:

    1. Find a default sshd_config script (you could get it from the downloadable tarball over at http://www.openssh.org).

    2. Upload your new sshd_config to the top level of a user account in ASCII mode.

    3. Make that use a member of the wheel group under WHM > Manage Wheel Group Users.

    4. Upload the following as script.exp to the top level of that users account in ASCII mode:
    Code:
    #!/usr/bin/expect -f
    set force_conservative 0
    set timeout -1
    spawn $env(SHELL)
    match_max 100000
    send -- "su -\r"
    expect -exact "su -\r
    Password: "
    send -- "PASSWORD\r"
    send -- "/bin/cp -f /home/USERNAME/sshd_config /etc/ssh/sshd_config\r"
    send -- "/etc/init.d/sshd restart\r"
    send -- "exit\r"
    expect eof
    
    Change USERNAME to the account name that you uploaded to and PASSWORD to be your root password.

    5. Upload the following perl CGI script as test.cgi to the users cgi-bin directory in ASCII mode and chmod it 711:
    Code:
    #!/usr/bin/perl
    
    print "content-type: text/html\n\n";
    system ("/usr/bin/expect /home/USERNAME/script.exp")
    print "Done";
    
    Again, replace USERNAME with the account name you uploaded to.

    6. Browse to test.cgi

    7. Try and login via SSH

    8. delete test.cgi and script.exp from the server

    9. Buy me a beer if it works
     
  3. MrL22

    MrL22 Active Member

    Joined:
    Jul 11, 2003
    Messages:
    34
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Tamworth, United Kingdom
    Nope didnt work, script ran said Done, but nothing else happend, just as the perl script said,,, cannot connect to ssh still...
     
  4. MrL22

    MrL22 Active Member

    Joined:
    Jul 11, 2003
    Messages:
    34
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Tamworth, United Kingdom
    Sorted

    No probs now, i have fixed it, written my own script...
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    It would be nice if you posted it here for anyone who has a similar problem in the future :)
     
  6. MrL22

    MrL22 Active Member

    Joined:
    Jul 11, 2003
    Messages:
    34
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Tamworth, United Kingdom
    Oh what a great idea, this is based on chirpy's method,,,

    first i created a file called "fixthebiatch.exp" containing the following -

    Code:
    #!/usr/bin/expect -f
    
    spawn su -
    expect "Password: " {
    send -- "xxxxxx\r" # Here xxxxxx is the password of root
    }
    
    expect "*]#*" {
    send -- "/bin/cp -f /home/USERNAME/sshd_config /etc/ssh/sshd_config\r" # REPLACE USERNAME
    }
    then i uploaded this to /home/USERNAME/ or you may know it as / in USERNAME's ftp

    next i created a perl script called "fixsshd.cgi" containing the following -

    Code:
    #!/usr/bin/perl 
    use CGI;
    my $cgi = CGI->new;
    print $cgi->header();
    system("/usr/bin/expect /home/USERNAME/fixthebiatch.exp"); # REPLACE USERNAME
    print qq{
    
    -----
    Well, ... all done here...
    };
    now upload fixsshd.cgi to /home/USERNAME/public_html (/public_html on FTP) and chmod it to 755...

    Obtain a copy of "sshd_config" from a distrobution of OpenSSH and upload it to the same location as "fixthebiatch.exp".

    Run the damn script (http://www.yoursite.com/fixsshd.cgi).... sure you dont need me to tell you how to do that....

    Now just login to WHM and restart your SSHD Server...

    Dont forget to delete the files off your site after....

    Thanks chirpy for guiding me in the right path...
     
    #6 MrL22, Jul 27, 2004
    Last edited: Jul 27, 2004
  7. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    My pleasure - thanks for posting what worked for you :)
     
Loading...

Share This Page