Add a User in Linux using Python Script Last Updated : 03 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Creating a user via command line in Linux is a tedious task. Every time someone joins your organization and you need to type a long Linux command rather than doing this you can create a python script that can ask for you the username and password and create that user for you. Examples: Input : Enter Username : John Password: **** Output : User successfully created with given credentials Below is the Python code - Python3 # importing linrary import os import subprocess import sys import getpass # add user function def add_user(): # Ask for the input username = input("Enter Username ") # Asking for users password password = getpass.getpass() try: # executing useradd command using subprocess module subprocess.run(['useradd', '-p', password, username ]) except: print(f"Failed to add user.") sys.exit(1) add_user() Output: After successfully creating the user type, use this command to get details of new user - cat /etc/passwd Comment More infoAdvertise with us Next Article Run Python Script using PythonShell from Node.js N Naveen Chaudhary 1 Follow Improve Article Tags : Python Write From Home python-utility Practice Tags : python Similar Reads Deleting a User in Linux using Python Script Deleting a user from your system or server via a python script is a very easy task. You just need to pass the username of the user and the script will remove the details and all the files of that user.This python script uses userdel Linux command to delete the user.You can directly use userdel comma 2 min read Telnet Automation / Scripting Using Python Telnet is the short form of Teletype network, which is a client/server application that works based on the telnet protocol. Telnet service is associated with the well-known port number - 23. As Python supports socket programming, we can implement telnet services as well. In this article, we will lea 5 min read GUI to generate and store passwords in SQLite using Python In this century there are many social media accounts, websites, or any online account that needs a secure password. Â Often we use the same password for multiple accounts and the basic drawback to that is if somebody gets to know about your password then he/she has the access to all your accounts. It 8 min read Run Python Script using PythonShell from Node.js Nowadays Node.js is the most attractive technology in the field of backend development for developers around the globe. And if someone wishes to use something like Web Scraping using python modules or run some python scripts having some machine learning algorithms, then one need to know how to integ 3 min read Python | Make a simple window using kivy Kivy is a platform independent as it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it Does not mean that it can not be used on Desktops 5 min read How to generate a unique username using Python A username is a unique name that is mainly used on websites and apps. A username is used to identify a person. For example, if your name is Akshay and you want to create your account on any social media app, here we need a username such that another person can find us. It is not possible to search b 4 min read Like