Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Jul 2003
    Posts
    27

    Angry Error in sshd_config and cannot edit file

    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!

  2. #2
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    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
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  3. #3
    Member
    Join Date
    Jul 2003
    Posts
    27

    Default

    Nope didnt work, script ran said Done, but nothing else happend, just as the perl script said,,, cannot connect to ssh still...

  4. #4
    Member
    Join Date
    Jul 2003
    Posts
    27

    Default Sorted

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

  5. #5
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    It would be nice if you posted it here for anyone who has a similar problem in the future
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

  6. #6
    Member
    Join Date
    Jul 2003
    Posts
    27

    Default

    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...
    Last edited by MrL22; 07-27-2004 at 02:14 PM.

  7. #7
    Super Moderator This forum account has been confirmed by cPanel staff to represent a vendor. chirpy's Avatar
    Join Date
    Jun 2002
    Location
    Go on, have a guess
    Posts
    13,495

    Default

    My pleasure - thanks for posting what worked for you
    Jonathan Michaelson

    Need your cPanel servers secured and tuned?
    cPanel Server Configuration, Security, Recovery and Antivirus/AntiSpam Services
    Developers of the most effective (and free) Firewall & Security Solution for cPanel Servers - csf
    http://www.configserver.com

Similar Threads & Tags
Similar threads

  1. File Manager Edit File function
    By santame in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 11-25-2003, 11:48 AM
  2. BUG in Edit File in File Manager
    By elitehst in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 10-13-2003, 02:46 PM
  3. File Manager Edit File bug
    By dariofg2 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 05-27-2003, 04:03 AM
  4. Getting Internal Server Error when I click 'edit' to edit ma
    By fog in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 10-12-2002, 12:13 PM
  5. # DO NOT EDIT THIS FILE - edit the master and reinstall
    By HOSTFORWEB in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 04-30-2002, 01:27 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube