Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #!/bin/bash
  2. # Script to add a user to Linux system
  3. if [ $(id -u) -eq 0 ]; then
  4. read -p "Enter username : " username
  5. read -p "Enter password : " password
  6. egrep "^$username" /etc/passwd >/dev/null
  7. if [ $? -eq 0 ]; then
  8. echo "$username exists!"
  9. exit 1
  10. else
  11. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  12. useradd -m -p $pass $username
  13. [ $? -eq 0 ] && echo "User has been added to system! Username: $username with password: $password"
  14. echo "congrats on the new user" || echo "Failed to add a user!"
  15. fi
  16. else
  17. echo "Only root may add a user to the system"
  18. exit 2
  19.  
  20. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement