SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP create linux user

    I need to know if there's a way of creating a linux user from php. I'm using ssh2_exec/ssh2_connect to login to ssh from php as root. How do I go from there to create a new user?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's distribution dependent, but "useradd" is the most common

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need a way that can also set the password
    I tried useradd with -p parameter but it's no good.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    "passwd" is the command to change passwords

    You could also look into editing the passwords file directly

  5. #5
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Disclaimer applies:

    It's a bad idea to configure SSH to allow you to login to a server as root.

    It's a very bad idea to configure a PHP script to be able to do this externally.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SituationSoap View Post
    Disclaimer applies:

    It's a bad idea to configure SSH to allow you to login to a server as root.

    It's a very bad idea to configure a PHP script to be able to do this externally.
    I appreciate your concern, however, this was not my question. It's not required to login as root. Other users can be created and restricted to certain tasks.

  7. #7
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by manilodisan View Post
    I appreciate your concern, however, this was not my question. It's not required to login as root. Other users can be created and restricted to certain tasks.
    You're still exposing administrative aspects of your server (and at some point, to create users, you're going to need to allow root over SSH via a PHP script, to do what you want to do) to the Internet. There are perhaps a dozen people in the world who could design a system that would do what you want to do without dramatically increasing the vulnerability footprint of a web server.

    Why is it that you need to do things this way? Perhaps we can help you come up with some sort of alternative which will provide similar functionality without making your server security into swiss cheese.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again, we're routing the discussion in the wrong way. I'm not, at all, concerned about the security of this application. I need to add/delete linux users automatically so that I can add/kill cron jobs the same way. That's why I need a working command which adds a user and a cron next to it that's all.

  9. #9
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by manilodisan View Post
    Again, we're routing the discussion in the wrong way. I'm not, at all, concerned about the security of this application. I need to add/delete linux users automatically so that I can add/kill cron jobs the same way. That's why I need a working command which adds a user and a cron next to it that's all.
    Or you could create a single cron job (which runs every minute or whatever interval you need) that looks for jobs to run in a database table, so that adding/removing jobs only requires access to a database and not root access to the system.

    There are lots of ways to do this easier than adding and removing users from the system.


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
  •