Created
August 10, 2019 16:36
-
-
Save Jackliu91/57321dbceafefe044892a51601a9f16d to your computer and use it in GitHub Desktop.
[add a restricted user] #bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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