I'm creating a python script that will create user accounts with an username and a password from an excile file. I'm having trouble finding a one line command that will create an user with a password though. I have tried "useradd" with the p-flag but it tells me that the password is wrong when I'm trying to login. I've also tried "adduser" but I haven't found a way yet. It seems like the user himself has to enter the password.
What I want to do: Create an user account with a password preferably with an one-line command.
Here is my python code at the moment that just creates the user accounts without a password:
#!/usr/bin/env python
import os
import openpyxl
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
excel_file = os.open("Names_mod.xlsx", os.O_RDONLY)
wb = openpyxl.load_workbook("Names_mod.xlsx")
sheet = wb.active
max_row = sheet.max_row
for i in range(1, max_row + 1):
name = sheet.cell(row = i, column = 5)
password = sheet.cell(row = i, column = 6)
addUser = "sudo useradd -m " + name.value
os.system(addUser)
chpasswd(from the second ranked answer) may be what you are looking for. All readers: feel free to make a full answer from this.newusers(provided bypasswdon Ubuntu): unix.stackexchange.com/q/21022/315749