Tutorial: Linux User Setup
Suppose we are creating a new user anitesh to our server.
- Create a user in the directory
- Create a home directory for new user and provide its sole ownership
- Set a password for the new user
- Set the default shell to be
/bin/bash - (Optional) Provide administrative aka
sudoaccess to the user
export username="anitesh"
echo "Creating user $username"
# Create a new user with the specified username
sudo useradd $username
# Create a home directory for the new user
sudo mkdir "/home/$username"
# Change the ownership of the home directory to the new user
sudo chown $username "/home/$username"
# Set a password for the new user (this will prompt for input)
sudo passwd $username
# Change the default shell for the new user to /bin/bash
sudo chsh --shell /bin/bash $username
# Add the new user to the 'sudo' group to grant administrative privileges
sudo adduser $username sudo