2

I have really bad problem. Here is the background:

I have a vps and I tried to use svn, but it fauls badly. I found in one site that the problem disappears if you reinstall ssh client and I did it. And while I was on the server the problem has been fixed.

The problem: it turns out that now I cannot login anymore on that server. It says ssh:

 connect to host myserver.com port 22: Connection refused

I suspect that when I reinstalled the ssh client the sshd server was uninstalled and the result is - no login.

What I have is FTP as well as PHP and I know root password. Is there any way I can install the openssh-server agan?

I ve tried following:

echo "MYPASSWORD" | /usr/bin/sudo -u root -S apt-get install -q openssh-server

and if I execute it in my local machine terminal it's working and it try to install sshd, but when I try to run it with php with:

exec('echo "MYPASSWORD" | /usr/bin/sudo -u root -S apt-get install -q openssh-server', $lines);
echo $lines;

it return nothing. I've tried with ls -la but the result is the same - on terminal it's ok, but from PHP it doesn't work.

Could you give me any advice how to solve that problem. It look like I need to turn into a hacker :)

3
  • 1
    The VPS provider isn't providing console access to the VPS?
    – andol
    Aug 10, 2011 at 11:51
  • Lesson learned I hope: after mucking about with ssh/sshd/libraries/pam over an ssh session, make sure you can login via ssh before closing your root shell.
    – MikeyB
    Aug 10, 2011 at 13:43
  • This sounds a bit like a you have FTP access to upload PHP scripts and you want to know how to use that to get shell access. That is a bit dodgy. Your VPS supplier should be able to help you out here.
    – dunxd
    Aug 10, 2011 at 13:47

4 Answers 4

3

If you have access as root over ftp you could do the following:

  1. Put package(s) required for sshd re-installation into some directory, e.g. /root/sshd_reloaded.
  2. Prepare a script, which installs that package and starts the sshd demon.
  3. FTP the packages to the proper location and the script to /etc/cron.hourly (or equivalent on your VPS system) and chmod it 0755 to make it executable. The general idea is to make cron pick it up and do the work for you. If you don't want to wait, you could probably put a file into /var/spool/cron/ to make cron execute a script which installs and starts sshd.
  4. Wait for the cron to pick up the new file and execute the job.
  5. Log into your VPS, change root password (it went in cleartext through FTP) and sin no more ;).

I'd recommend trying it first on the local machine -- it will make debugging easier. Only when you are sure all elements work, do it on the remote host.

The whole trick hinges on ability of being able to FTP remotely as root to a non-chrooted environment (which is not the way I'd recommend to configure FTP server).

2
  • That is downright cunning; you have my respect, sir! Though I agree about any ftp server allowing this being misconfigured to the point of perversity.
    – MadHatter
    Aug 10, 2011 at 13:49
  • Thanks, I will try, but probably is better to get support from the hosting company.
    – Nik
    Aug 10, 2011 at 15:55
3

I don't think you have much option but to try re-starting your VPS.

If that doesn't fix the problem then boot your system into recovery mode (if you can) and take a look at your logs and the sshd configuration file to see if they can help narrow down the problem.

Failing that you will have to get your vps provider to help.

1
  • Thanks for the idea, actually it's not a bad to try to restart the server.
    – Nik
    Aug 10, 2011 at 15:58
2

Unless your Apache user has sudo permissions or you are running Apache as root, sorry, you cannot install ssh like that. Also reinstalling stuff on Linux rarely helps; if anything, you should need to restart the sshd process and if that does not help, see if there's something wrong with its configuration file.

One possible way MIGHT be to modify /etc/sudoers file at your localhost to contain sudo privileges for your Apache user, then upload that file to your server (if you can connect there as root), and try run your script again. But then again, I suspect this does not help even if you succeed in this, since problem might be in your configuration files.

You can also try to modify your script to be sudo -u root -S /etc/init.d/ssh restart after you grant the sudo privileges for Apache user.

Oh! One more thing. If you can connect there as root, you may also download the log files and see if they reveal why your sshd does not start or why it has fallen down.

1

There could be ways to log in to your server, but these are methods that are not discussed here I think ( containing php shells , connectback shell etc...).

I agree with the above answer that you would need some sort of remote console on your vps. A lot of providers support these methods ( rebooting into resque mode, giving a web kvm, ...).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .