Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #!/bin/bash
  2. ##
  3. # update and upgrade server
  4. ##
  5. apt-get update
  6. apt-get upgrade -y
  7. apt-get dist-upgrade -y
  8. apt-get autoremove -y
  9. apt-get install git -y
  10.  
  11. ##
  12. # create new user to admin server via ssh
  13. ##
  14. USER="YourUsername"
  15. PASSWORD="GiveMeYourPassBaby"
  16. HOME="/home/$USER"
  17. HOSTNAME="www.example.com"
  18. SSH_KEY="your_id.rsa.pub"
  19. ###############################################################################
  20. # HOW TO GENERATE SSH_KEY === >
  21. # on your local machine open terminal and type:
  22. # ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  23. # Now appears the text: generating public/private rsa key pair.
  24. # Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
  25. # Enter passphrase (empty for no passphrase): [Type a passphrase]
  26. # Enter same passphrase again: [Type passphrase again]
  27. # cat ~/.ssh/id_rsa.pub copy and paste in SSH_KEY !!!
  28. ###############################################################################
  29. # quietly add a user without password
  30. adduser --system --quiet --shell=/bin/bash --home=$HOME --gecos '$USER' --group $USER
  31. usermod -aG sudo $USER
  32. # set password
  33. echo "$USER:$PASSWORD" | chpasswd
  34.  
  35. ##
  36. # create authorized_keys access on the server
  37. ##
  38.  
  39. mkdir -p $HOME/.ssh
  40. chmod 700 $HOME/.ssh
  41. echo "$SSH_KEY" >> $HOME/.ssh/authorized_keys
  42. chown $USER:$USER $HOME/.ssh*
  43. chown $USER:$USER $HOME/.ssh/authorized_keys
  44. chmod 600 $HOME/.ssh/authorized_keys
  45. rm /etc/ssh/sshd_config
  46. cat <<EOF > /etc/ssh/sshd_config
  47. # Package generated configuration file
  48. # See the sshd_config(5) manpage for details
  49.  
  50. # What ports, IPs and protocols we listen for
  51. Port 22
  52. # Use these options to restrict which interfaces/protocols sshd will bind to
  53. #ListenAddress ::
  54. #ListenAddress 0.0.0.0
  55. Protocol 2
  56. # HostKeys for protocol version 2
  57. HostKey /etc/ssh/ssh_host_rsa_key
  58. HostKey /etc/ssh/ssh_host_dsa_key
  59. HostKey /etc/ssh/ssh_host_ecdsa_key
  60. HostKey /etc/ssh/ssh_host_ed25519_key
  61. #Privilege Separation is turned on for security
  62. UsePrivilegeSeparation yes
  63.  
  64. # Lifetime and size of ephemeral version 1 server key
  65. KeyRegenerationInterval 3600
  66. ServerKeyBits 1024
  67.  
  68. # Logging
  69. SyslogFacility AUTH
  70. LogLevel INFO
  71.  
  72. # Authentication:
  73. LoginGraceTime 120
  74. PermitRootLogin no
  75. StrictModes yes
  76.  
  77. RSAAuthentication yes
  78. PubkeyAuthentication yes
  79. AuthorizedKeysFile %h/.ssh/authorized_keys
  80.  
  81. # Don't read the user's ~/.rhosts and ~/.shosts files
  82. IgnoreRhosts yes
  83. # For this to work you will also need host keys in /etc/ssh_known_hosts
  84. RhostsRSAAuthentication no
  85. # similar for protocol version 2
  86. HostbasedAuthentication no
  87. # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
  88. #IgnoreUserKnownHosts yes
  89.  
  90. # To enable empty passwords, change to yes (NOT RECOMMENDED)
  91. PermitEmptyPasswords no
  92.  
  93. # Change to yes to enable challenge-response passwords (beware issues with
  94. # some PAM modules and threads)
  95. ChallengeResponseAuthentication no
  96.  
  97. # Change to no to disable tunnelled clear text passwords
  98. PasswordAuthentication no
  99.  
  100. # Kerberos options
  101. #KerberosAuthentication no
  102. #KerberosGetAFSToken no
  103. #KerberosOrLocalPasswd yes
  104. #KerberosTicketCleanup yes
  105.  
  106. # GSSAPI options
  107. #GSSAPIAuthentication no
  108. #GSSAPICleanupCredentials yes
  109.  
  110. X11Forwarding yes
  111. X11DisplayOffset 10
  112. PrintMotd no
  113. PrintLastLog yes
  114. TCPKeepAlive yes
  115. #UseLogin no
  116.  
  117. #MaxStartups 10:30:60
  118. #Banner /etc/issue.net
  119.  
  120. # Allow client to pass locale environment variables
  121. AcceptEnv LANG LC_*
  122.  
  123. Subsystem sftp /usr/lib/openssh/sftp-server
  124.  
  125. # Set this to 'yes' to enable PAM authentication, account processing,
  126. # and session processing. If this is enabled, PAM authentication will
  127. # be allowed through the ChallengeResponseAuthentication and
  128. # PasswordAuthentication. Depending on your PAM configuration,
  129. # PAM authentication via ChallengeResponseAuthentication may bypass
  130. # the setting of "PermitRootLogin without-password".
  131. # If you just want the PAM account and session checks to run without
  132. # PAM authentication, then enable this but set PasswordAuthentication
  133. # and ChallengeResponseAuthentication to 'no'.
  134. UsePAM yes
  135. EOF
  136. service ssh restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement