Guest User

Untitled

a guest
Oct 26th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #!/bin/sh
  2. sudo su
  3. #============================
  4. #Create deploy user
  5. DEPLOY_USER=deploy
  6. DEPLOY_USER_PASSWORD=deploy
  7. #============================
  8. #create deploy user
  9. adduser --disabled-password --gecos "" ${DEPLOY_USER}
  10. sudo adduser ${DEPLOY_USER} sudo
  11. echo "${DEPLOY_USER}:${DEPLOY_USER_PASSWORD}" | chpasswd
  12.  
  13. #crreate .ssh folder
  14. mkdir -p /home/${DEPLOY_USER}/.ssh
  15. chmod 700 /home/${DEPLOY_USER}/.ssh
  16. #cat the key for this user to .ssh/authorized_keys
  17. touch /home/${DEPLOY_USER}/.ssh/authorized_keys
  18.  
  19. #change home file owned by deploy user
  20. chown ${DEPLOY_USER}:${DEPLOY_USER} /home/${DEPLOY_USER} -R
  21.  
  22. #turnoff ssh password authentication
  23. if grep -q '^PasswordAuthentication.*$' "/etc/ssh/sshd_config"; then
  24. echo "PasswordAuthentication is not commented, turning off explicitly..."
  25. sed -i 's/^PasswordAuthentication.*$/PasswordAuthentication no/g' /etc/ssh/sshd_config
  26. elif grep -q '^#PasswordAuthentication' "/etc/ssh/sshd_config";
  27. then
  28. echo "PasswordAuthentication is commented , turning off explicitly..."
  29. sed -i 's/^#PasswordAuthentication.*$/PasswordAuthentication no/g' /etc/ssh/sshd_config
  30. else
  31. echo "PasswordAuthentication is not turned on , skipping..."
  32. fi
  33. sudo service ssh restart
  34.  
  35. #switch to deploy user
  36. su - deploy
  37. #exit deploy user
  38. exit
  39. #exit root
  40. exit
Add Comment
Please, Sign In to add comment