Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 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.  
  7. grep "^$username" /etc/passwd > /dev/null
  8. if [ $? -eq 0 ]; then
  9. echo "$username already exists!"
  10.  
  11. else
  12. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  13. useradd -p $pass $username
  14.  
  15. if [ $? -eq 0 ]; then
  16. echo "User $username has been added to system"
  17. else
  18. echo "Failed to add user $username"
  19.  
  20. fi
  21.  
  22. fi
  23.  
  24. else
  25. echo "Only root may add a user to the system"
  26. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement