Sven Slootweg
Sven Slootweg

Reputation: 3793

How to securely maintain a persistent SSH connection in PHP?

I am currently working on a VPS panel that uses a master-slave model. One master server runs a panel written in PHP, and manages multiple slave servers via SSH. The slave servers are accessed via a limited account, that can sudo to specific server administration-related commands, and all interaction is logged in a directory that the account itself does not have access to.

I am currently using PHP-SSH2, but this approach has a few problems:

Right now, I'm trying to solve the last problem primarily.

There are several possible solutions I have run across, but all of them have an issue of some sort:

The following are not an option:

In practice, I am seeing pageload times of sometimes over a minute when multiple servers have to be contacted for a pageload. This is obviously not acceptable for a VPS panel.

My goal is to have some kind of implementation that avoids the connection overhead that is introduced when using PHP-SSH2. What would be the best way to do this, in a secure manner, while introducing a minimal amount of dependencies on the slave servers?

Upvotes: 4

Views: 2343

Answers (2)

user520476
user520476

Reputation:

You could use autossh, and create reverse (portforward) tunnels with autossh. Then let your php application talk against those reverse ssh ports. If the ssh connection fails, autossh will keep trying to recreate the connection. Your php app will fail to connect to the reverse tunnel and not even timeout.

Upvotes: 1

Vladimir Panteleev
Vladimir Panteleev

Reputation: 25187

How about option 3, but writing the daemon in PHP as well? That's the route I'm attempting with my own similar project.

You could use a FIFO file instead of sockets to communicate with it.

Upvotes: 0

Related Questions