1

I'm trying to build a baseline tools installer for Kali Linux, basically, a script that installs all the tools I usually have to install manually, but also creates a new user and switches to it.

My script so far looks like this:

# --------------
# Imports
# --------------
import os
import getpass
# --------------
# Get Username
user = getpass.getuser()
# -
# Colors
colorGreen = "\033[1; 32; 40m end="""
# -
# --------------
# Functions
# --------------

# Update & Upgrade


def upgrade():
    os.system('sudo apt update && sudo apt upgrade')
# -

# Add new User


def addUser():
    print("### Creating a Low Priv User ###")
    user = input("Choose a username: ")
    os.system('sudo adduser ' + user)
    print("### Adding new user to Sudo ###")
    os.system("sudo usermod -aG sudo " + user)
    os.system("sudo chsh -s /bin/bash " + user)
    print("### Done ###")
    print("### Switching to new user... ###")
    os.system("su " + user)
    print("### Done! Welcome {}".format(user))


# --------------
# Function Calls
# --------------
upgrade()
addUser()
# -

As soon as I reach the end, which is os.system("su " + user), the script naturally stops. su %username% is the command to switch to the newly created user.

Ideally, I want that the script keeps running after that, so I am able to install the tools within the newly created user.

Is there a way to achieve this? Or is there another way to do this? I know I could use something like git clone NewTool/home/{user}/opt/ and go from there, but that seems inconvenient.

It would be great if someone can point me in the right direction!

Cheers

Stefan Rows
  • 67
  • 10

1 Answers1

0

Did some digging and figured out a way to work around my problem.

Instead of changing the user, I simply declared a variable user that stores the username.

Then, once the user is created, I just use a different syntax, so that the new user is used for the installation.

Example:

user = "newUser"
os.system('sudo -u {} sudo apt install nixnote2 -y'.format(user))

This solves my problem for now.

Stefan Rows
  • 67
  • 10