Skip to content

Instantly share code, notes, and snippets.

@Jackliu91
Created August 10, 2019 16:36
Show Gist options
  • Save Jackliu91/57321dbceafefe044892a51601a9f16d to your computer and use it in GitHub Desktop.
Save Jackliu91/57321dbceafefe044892a51601a9f16d to your computer and use it in GitHub Desktop.
[add a restricted user] #bash
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Please enter username."
else
USERNAME=$1
PASSWD=$USERNAME
HOME=/home/$USERNAME
BIN_PATH=$HOME/bin
echo "adding user: [$USERNAME]"
useradd -m -s /bin/rbash $USERNAME
echo $USERNAME:$PASSWD | chpasswd
#make password expire
passwd -e $USERNAME
chown root:$USERNAME $HOME/.bashrc $HOME/.bash_profile
chmod 640 $HOME/.bashrc $HOME/.bash_profile
mkdir $BIN_PATH
echo "export PATH=$BIN_PATH" >> $HOME/.bash_profile
ln -s /usr/bin/ssh $BIN_PATH/ssh
echo "done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment