Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.50 KB | None | 0 0
  1. #!/bin/bash
  2. # Script to add a user to Linux system
  3.  
  4. if [ $(id -u) -eq 0 ]; then
  5.     read -p "Enter username : " username
  6.     read -p "Enter password : " password
  7.    
  8.     grep "^$username" /etc/passwd >/dev/null
  9.     if [ $? -eq 0 ]; then
  10.         echo "$username already exists!"
  11.    
  12.     else
  13.         pass=$(perl -e 'print crypt($ARGV[0], "password")'$password)
  14.         useradd -p $pass $username
  15.    
  16.         if [ $? -eq 0 ] ; then
  17.             echo "User $username has been added to system”
  18.         else
  19.           echo "Failed to add user $username"
  20.         fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement