yandexMorehod / adduser.sh
SBlack's picture
Update adduser.sh
f517392
raw
history blame contribute delete
725 Bytes
#!/bin/bash
# Check if the current user is a superuser
if [ "$(id -u)" != "0" ]; then
echo "This script must be run with superuser privileges."
exit 1
fi
# Create a new user
user="user"
password="123"
# Check if a user with the given name already exists
if id "$user" &>/dev/null; then
echo "User with the name $user already exists."
exit 1
fi
# Create a user with the specified name and password
useradd -m -p $(openssl passwd -1 "$password") "$user"
# Display information
echo "User $user has been successfully created."
# Switch to the new user and perform additional actions
su -l "$user" -c 'echo "Additional actions to be performed on behalf of the new user"; bash'
# Terminate the script
exit 0