sysconfig/debian-add-user.sh
2022-06-18 11:58:52 +08:00

49 lines
1.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

echo "Usage: setup.sh [USER]"
echo "Example: setup.sh alice"
if [ v$1 != v ]
then
NewUser=$1
else
echo "=== Enter new <<UserName>> (leave blank for default 'adot'):"
read -p ">>> " NewUser
if [ ! $NewUser ]
then
echo Use default new user: adot
NewUser=adot
fi
fi
echo "=== Add a new user $NewUser"
useradd $NewUser
# usermod -a -G sudo $NewUser # Add to sudo group
passwd $NewUser
mkdir /home/$NewUser
chown $NewUser:$NewUser /home/$NewUser
chmod 700 /home/$NewUser
# Set default shell in /etc/passwd
# Debian 10 default to /bin/sh
sed -i "s|/home/$NewUser:/bin/sh$|/home/$NewUser:/bin/bash|g" /etc/passwd
# Debian 9 default to empty
sed -i "s|/home/$NewUser:$|/home/$NewUser:/bin/bash|g" /etc/passwd
echo "=== Allow the new user $NewUser to sudo without password"
#usermod -a -G sudo $NewUser # Add to sudo group # Option 1: add user to %sudo group
echo "$NewUser ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/${NewUser//./-} # Option 2: add a user file into /etc/sudoers.d/
chmod a-w /etc/sudoers.d/${NewUser//./-}
echo
# 注意,由 root 为新用户创建的配置文件的 owner 是 root而不是新用户
if [ $NewUser = 'adot' ]
then
source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser
else
echo "=== Configure $NewUser home with standard scripts? <y> for yes, <<anything else>> for no"
read -p ">>> " YesOrNo
if [ $YesOrNo = 'y' ]
then
source /faronear/fon/sysconfig/home-config.sh /faronear/fon/sysconfig/nixhome /home/$NewUser
fi
fi