Skip to content

Instantly share code, notes, and snippets.

@ramazanpolat
Created November 6, 2013 00:45
Show Gist options
  • Save ramazanpolat/7329013 to your computer and use it in GitHub Desktop.
Save ramazanpolat/7329013 to your computer and use it in GitHub Desktop.
This script generates linux users which CAN NOT login to shell but CAN change his/her password with SSH." It is ideal to have those type of users if you are using softwares using OS authentication (eg. IBM DB2)"
#!/bin/bash
if [ $# -eq 0 ]
then
echo "This script generates linux users which CAN NOT login to shell but CAN change his/her password with SSH."
echo "It is ideal to have those type of users if you are using softwares using OS authentication (eg. IBM DB2)"
echo "USAGE : $0 {username} "
echo " username : prefix of file name to be generated"
echo "EXAMPLE:"
echo " $0 "
echo "Author: Ramazan POLAT - [email protected]"
exit 1
fi
USERNAME=$1
echo "Adding user : $USERNAME ..."
sudo useradd -m -d /home/$USERNAME -s /bin/bash -c "login is forbidden for this user" $USERNAME -N -g users
echo "Configuring permissions..."
chown root:users /home/$USERNAME
chmod 555 /home/$USERNAME
echo "trap '' 2" >> /home/$USERNAME/.bash_profile
echo "passwd" >> /home/$USERNAME/.bash_profile
echo "logout" >> /home/$USERNAME/.bash_profile
passwd $USERNAME
echo "The user [$USERNAME] created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment