I've been trying to run Linux terminal commands via a Python script, and I can't seem to do anything with what I've found so far.
This is what I've done so far:
import os
import crypt
def addnewuser():
uname=raw_input("Select Username")
upass=raw_input("Select Password")
#The encryption module seems to solve the obvious security leak,
#but I still don't know whether even the exposed encrypted password is safe or not.
ucrypt=crypt.crypt(upass,"123")
os.system("useradd -m -p "+upass+" "+uname)
addnewuser()
This has been asked before, but I can't seem to find a solution, because whenever I run the script, nothing changes when I try to display all user when I'm typing
compgen -u
on the terminal.
Update 1: I want to make the process secure, and I've found that I can protect the sudo password from being recorded in the terminal history by using the stdout file. How can I write there with python to create users?
Update 2: I have managed to avoid some security leaks by encrypting the user password by using the encryption module in my code. But if the intruder has the encrypted password, isn't it the same thing?
The main purpose of this is for me to learn how to develop adminstration tools, preferrably in Python.
I use Python 2.7, as well as PythonIDLE, on Ubuntu 16.04.
Thank you for your help.