lockacc

LockAcc

Lock Account User Management System

Script to delete, create, lock, and change passwords for users.

Script runs and gives choice for input. a b c d e etc...

Script to lock username. Asks for what user you want to lock, delete, create, lock or change password.

Expire, unlock password.

In [ ]:
import os
import getpass
In [ ]:
#Menu that displays all the options. 
#eg 1 to delete user
#2 to create user
#3 to lock user
#4 to change password
print('a to delete a user, b to create a user, c to lock a user, e to unlock a locked account, f to expire a users password') 
selectchoic = raw_input('Select task by letter: ')

if str('f') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to password expire: ")
    os.system('sudo passwd -e ' + locusa) 
    #os.system('sudo pgrep -u ' + locusa)
    #os.system('sudo killall -KILL -u ' + locusa)



if str('e') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to unlock: ")
    os.system('sudo passwd -u ' + locusa) 
    #os.system('sudo pgrep -u ' + locusa)
    #os.system('sudo killall -KILL -u ' + locusa)

#selectchoic = int(selectchoic)
if str('c') in selectchoic:
#lockusr = raw_input('Do you want to lock a user? y/n ')
#if 'y' in lockusr:
    locusa = raw_input("User to lock: ")
    os.system('sudo passwd -l ' + locusa) 
    os.system('sudo pgrep -u ' + locusa)
    os.system('sudo killall -KILL -u ' + locusa)
In [ ]:
#deleusr = raw_input('Do you want to delete a user? y/n ')

#if 'y' in deleusr:
if str('a') in selectchoic:
    print 'y'
    locusa = raw_input("User to Delete: ")
    os.system('sudo passwd -l ' + locusa) 
    os.system('sudo pgrep -u ' + locusa)
    os.system('sudo killall -KILL -u ' + locusa)
    os.system('sudo userdel -r ' + locusa)
    
In [ ]:
#makeusr = raw_input('Do you want to create a user? y/n ')

#if 'y' in makeusr:
if str('b') in selectchoic:
    print 'y'
    cruer = raw_input('Username to Create: ')
    #crpas = getpass.getpass('Password for ' + cruer + ': ')
    usdir = ('sudo useradd ' + cruer)
    os.system(usdir)
    #chdirz = ('sudo passwd ' + cruer + ' ' + crpas)
Do you want to create a user? y/n y
y
Username to Create: libcs
Password for libcs: ········
In [ ]:
#Change a password of a user
#Why not just edit the shadow file and paste encrupted
#password in there?

#This isn't working right now. look at subprocess pipe.
#chanpass = raw_input('Do you want to change a password? y/n ')

#if 'y' in chanpass:
#if str('d') in selectchoic:
#    print 'y'
#    chpasr = raw_input('Username to change password: ')
#    chpasz = getpass.getpass('Enter new password: ')
#    chdirz = ('sudo passwd ' + chpasr + ' ' + chpasz)
    
In [ ]:
#if str('t') in selectchoic:
    

Comments

Comments powered by Disqus