How do I add users using Python scripts on a Linux machine

Jan Dries jan.dries at dcube-resource.be
Tue Jan 2 11:03:47 EST 2007


Ivan Voras wrote:
> Ramdas wrote:
>> Well,
>>
>> I need to add users from a web interface for a web server, which runs
>> only Python. I need to add users, set quotas and in future even look at
>> managing ip tables to limit bandwidth.
>>
>> I know os.system(), but this has to be done through a form entry
>> through a web interface.
>>
>> Anyways thanks, do advise if there more pythonic solutions
> 
> What you're looking for is actually a pretty complex thing. You *could*
> in theory manage /etc/passwd (and its "shadow" file) - you can find
> crypto primitives like MD5 and DES on the 'net, but note that you must
> run your script under the 'root' account in order to write (and even
> read!) the passwd database. The same goes for using os.system and the
> built-in OS utility. Be aware of security implications if you're running
> your web server under the root account.

A solution that is both more pythonic and avoids the problems listed 
above would be to migrate user management from /etc/passwd to an LDAP 
(though pam_ldap). That's the approach I took in a similar situation. 
Sure, it adds the overhead of setting up and running an LDAP, but 
managing users and their quota through python_ldap is much cleaner and 
more flexible than doing so using os.system(), certainly from within a 
web application.
That doesn't alter the fact though that security must be properly 
considered in any application that can add users.

Regards,
Jan



More information about the Python-list mailing list