Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #!/bin/bash
  2. echo 'Non-root username:'
  3. read user
  4. echo 'Non-root users password:'
  5. read pwd
  6. echo 'New ssh tunnels port:'
  7. read port
  8. # Adding non-root user and copying verification
  9. useradd -m -s $(which bash) -G sudo $user
  10. /usr/bin/passwd $user <<EOF
  11. $pwd
  12. $pwd
  13. EOF
  14. /usr/bin/expect << EOF
  15. spawn ssh-copy-id -i /root/.ssh/id_rsa $user@146.71.76.161
  16. expect {
  17. "continue" { send "yes\n"; exp_continue }
  18. "Password:" { send "$pwd\n"; }
  19. }
  20. EOF
  21. # Rewriting content of the ssh config
  22. echo -n "Port $port
  23. Protocol 2
  24. HostKey /etc/ssh/ssh_host_rsa_key
  25. HostKey /etc/ssh/ssh_host_dsa_key
  26. HostKey /etc/ssh/ssh_host_ecdsa_key
  27. UsePrivilegeSeparation yes
  28. KeyRegenerationInterval 3600
  29. ServerKeyBits 1024
  30. SyslogFacility AUTH
  31. LogLevel SILENT
  32. LoginGraceTime 30
  33. PermitRootLogin no
  34. StrictModes yes
  35. RSAAuthentication yes
  36. PubkeyAuthentication yes
  37. IgnoreRhosts yes
  38. RhostsRSAAuthentication no
  39. HostbasedAuthentication no
  40. PermitEmptyPasswords no
  41. ChallengeResponseAuthentication no
  42. X11Forwarding yes
  43. X11DisplayOffset 10
  44. PrintMotd no
  45. PrintLastLog yes
  46. TCPKeepAlive yes
  47. AcceptEnv LANG LC_*
  48. Subsystem sftp /usr/lib/openssh/sftp-server
  49. UsePAM yes" > /etc/ssh/sshd_config
  50. apt-get update && apt-get upgrade -qq
  51. # Cleaning logs
  52. find /var/log -type f -delete
  53. find /var/log -type f -regex ".*\.gz$"
  54. find /var/log -type f -regex ".*\.[0-9]$"
  55. # Adding firewall
  56. apt-get install ufw -qq
  57. ufw allow $port/tcp
  58. echo "y" | ufw enable
  59. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement