SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Location
    Dallas, TX
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Connect to SSH server

    How would I go about using php to connect to another server using php and exec commands on that other server through SSH?

    I took a look at sockets but I cant find any reference to ssh.

    Thanks
    Jeremy

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    Earth
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jeremy try just executing shell commands using backticks, system or similar... like

    `ssh login@remoteserver.com "ls -al"`
    Last edited by JimQH; Dec 6, 2003 at 00:40.
    http://www.quadrahosting.com/
    Multi Domain Web Hosting service for newbie and experienced developers

  3. #3
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Location
    Dallas, TX
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that, but the ssh client prompts for the password after, so the cmds dont get executed.

    Looking at the man docs of ssh I see no way to add the password to the ssh connect command line.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    Earth
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to set up ssh to use public key. create your own set of public / private keys using ssh-keygen -t dsa it will save these keys in ~/.ssh/id_dsa (the private key) and id_dsa.pub

    Then insert the id_dsa.pub into the target system's ~/.ssh/authorized_keys (or authorized_keys2 - see their sshd manual)

    Once this has been set up you can use ssh without being prompted for password.
    http://www.quadrahosting.com/
    Multi Domain Web Hosting service for newbie and experienced developers

  5. #5
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Location
    Dallas, TX
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this. I can get machine one to ssh into machine 2 but not machine 2 to ssh into machine 1 which is what I really need.

    Also this is being build for a script availible for people to use. So I REALLY need it to be portable. Is there no way at all for PHP to recognize there is a prompt and enter the password?

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so you need to create a key on machine 2 and copy it to the .ssh/authorized_keys file on machine 1.

    It cannot be portable without the user going through the same rigamaroll to create keys. Sorry. It's a security feature.
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •