Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Script to add a user to Linux system
  4. if [ $(id -u) -eq 0 ]; then
  5. read -p "Enter username : " username
  6. read -s -p "Enter password : " password
  7. egrep "^$username" /etc/passwd >/dev/null
  8. if [ $? -eq 0 ]; then
  9. echo "$username exists!"
  10. exit 1
  11. else
  12. pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  13. useradd -m -p $pass $username
  14. [ $? -eq 0 ] && echo "User has been added to system!" || 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. fi
  20.  
  21. # adding user to sudoers list
  22. echo $username" ALL=(ALL) ALL" >> /etc/sudoers
  23.  
  24. # Configuring ssh file. Removing root login, allowing only the user to login etc.
  25. sed '/PermitRootLogin yes/d' /etc/ssh/sshd_config
  26. sed '/#Port 22/d' /etc/ssh/sshd_config
  27. echo "PermitRootLogin no" >> /etc/ssh/sshd_config
  28. echo "AllowUsers "$username >> /etc/ssh/sshd_config
  29. echo "Port 17576" >> /etc/ssh/sshd_config
  30. echo "service sshd restart"
  31.  
  32. # Blocking ssh from other IPs.
  33. echo "sudo iptables -A INPUT -p tcp -s 180.151.30.100 --dport 17576 -j ACCEPT"
  34. echo "sudo iptables -A INPUT -p tcp -s 180.151.30.99 --dport 17576 -j ACCEPT"
  35. echo "sudo iptables -A INPUT -p tcp --dport 22 -j DROP"
  36. echo "sudo iptables -A INPUT -p tcp --dport 17576 -j DROP"
  37. echo "sudo iptables-save"
  38. echo "service sshd restart"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement