Results 1 to 16 of 16
Thread: Run shell commands with PHP ?
-
05-31-2005, 01:57 AM #1Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
Run shell commands with PHP ?
What is the best way to run a command like ... adduser or deluser or service restart on a box from a remote webbox using php?
ServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 02:10 AM #2Web Hosting Master
- Join Date
- Jun 2000
- Location
- Washington, USA
- Posts
- 5,990
I typically use something similiar to sudo, and run the PHP scripts via CGI, so that they are running as a different user than Apache. That technique works fairly well.
-
05-31-2005, 02:13 AM #3Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
John, can you expand more on what exactly you do? (I also don't see you on IRC)
ServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 02:19 AM #4Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
I am looking for something to
1) Log into a remote box
2) Add a user account
3) Set its password
4) Run a script
5) Log out
something along those lines.
Can someone please details one of the following
1) running commands 1 at a time to the target box via an SSH trust connection / RSA keys
2) Backend daemon accepting commandsServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 02:27 AM #5Web Hosting Master
- Join Date
- May 2001
- Location
- @ Work - Usually!
- Posts
- 835
Allow exec in PHP.INI and the chmod 6755 the script and chown the script to a root user.
Technically that should work - I have not tested it - but "obviously" dont leave the script in an unprotected public folder.
-
05-31-2005, 02:35 AM #6Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
Thats for exec on the same server .... the commands are coming from webbox and the commands are being executed on a remote box without APACHE ...
please read my description before you postServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 05:14 AM #7Web Hosting Master
- Join Date
- Mar 2004
- Posts
- 1,303
Originally posted by The Broadband Man
John, can you expand more on what exactly you do? (I also don't see you on IRC)
add #!/usr/bin/php to the begining of the script.
PHP Code:<?
#!/usr/bin/php
// the rest is your php
// ...
?>
-
05-31-2005, 05:30 AM #8Junior Guru Wannabe
- Join Date
- Jan 2005
- Location
- UK
- Posts
- 94
He wants to be able to SSH into a server from a webserver. I've been trying to do this, but I do not think it is possible with PHP.
-
05-31-2005, 05:59 AM #9Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
He wants to be able to SSH into a server from a webserver. I've been trying to do this, but I do not think it is possible with PHP.PHP Code:<?php
$key = 'someencryptedkeytohost';
// Establish a connection
$conn = ssh2_connect('foo.com');
if (!$conn) { die("Cannot connect"); }
// Verify using remote key
if (ssh2_fingerprint($conn,SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX) != $key)
{
die("Cannot verify server using key");
}
// -- OR --
// Verify using username password
if (!ssh2_auth_password($conn, 'username', 'password'))
{
die("Cannot authenticate using username/password");
}
// Open a shell, and execute a command
$shell=ssh2_shell($conn, 'xterm');
fwrite( $shell, "ls -la\n");
?>
-
05-31-2005, 07:28 AM #10Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
I've tried this, it doesn't really work all that well. Also, is RSA key the only way to do this?
ServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 08:00 AM #11Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
is ssh2_connect() is a php 5 function because I get
Fatal error: Call to undefined function: ssh2_connect()
1) Any php4 alternatives?
2) Anyone know if modernbill and kayako work on php5?Last edited by The Broadband Man; 05-31-2005 at 08:06 AM.
ServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 10:32 AM #12Junior Guru Wannabe
- Join Date
- Jan 2005
- Location
- UK
- Posts
- 94
Originally Posted by php.net
-
05-31-2005, 11:08 AM #13Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Also, is RSA key the only way to do this?
-
05-31-2005, 11:24 AM #14Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
Yeah I just saw - however ssh2_connect is a php5 function ... any php4 alternatives?
ServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!
-
05-31-2005, 11:30 AM #15Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Its a PECL extension. Try http://pecl.php.net/package/ssh2 for more information.
-
05-31-2005, 01:29 PM #16Web Hosting Master
- Join Date
- Jul 2004
- Location
- New York, NY
- Posts
- 2,181
Ooo I see - thank you kindly sir
i downloaded it but it won't install ... hrm - im lostServGrid - www.servgrid.com - Affordable and Reliable SSD Cloud Solutions
Premium 10G Network, 2(N+1) Powerplant and SSD Performance
Web, Reseller, KVM VPS, Storage and Private Cloud Hosting
Click here to see our SSD Benchmarks!