changeing users on linux

D

darkchild50

how would i go about makeing a program in python that asks for username
and password and changes to that user?
 
M

Mike Meyer

how would i go about makeing a program in python that asks for username
and password and changes to that user?

For some definition of "changes to that user":

# Untested code
from pwd import getpwnam
from os import setuid

setuid(getpwnam(raw_input("Who do you want to be? "))[2])

I don't recommend the one-liner version for production code, though.
You didn't say what the password was for, so I skipped asking for it.

<mike
 
J

jepler

You didn't say what the password was for, so I skipped asking for it.

You're a real comedian.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDdgLGJd01MZaTXX0RAmHuAKCdA34dZKcLDdH0pshC4u/PTx5OVwCcDy9e
N0h3ihmTgKrJtdGwRy8Dfcc=
=Pkm2
-----END PGP SIGNATURE-----
 
M

Mike Meyer

the password is for loging into root

The setuid call will fail unless you're already root. You can't, as
some user other than root, change your userid, so the answer to
the original question with the added restriction is "You can't".

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top