Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Script to add a user to Linux system
- if [ $(id -u) -eq 0 ]; then
- read -p "Enter username : " username
- read -p "Enter password : " password
- grep "^$username" /etc/passwd > /dev/null
- if [ $? -eq 0 ]; then
- echo "$username already exists!"
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -p $pass $username
- if [ $? -eq 0 ]; then
- echo "User $username has been added to system"
- else
- echo "Failed to add user $username"
- fi
- fi
- else
- echo "Only root may add a user to the system"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement