浏览代码

Merge pull request #28 from lukecyca/sshd-sec

SSH security improvements
Alex Payne 11 年前
父节点
当前提交
da7581becd
共有 4 个文件被更改,包括 96 次插入1 次删除
  1. 1
    1
      README.textile
  2. 3
    0
      roles/common/handlers/main.yml
  3. 5
    0
      roles/common/tasks/security.yml
  4. 87
    0
      roles/common/templates/etc_ssh_sshd_config.j2

+ 1
- 1
README.textile 查看文件

39
 * Web hosting (ex: for your blog) via "Apache":https://www.apache.org/.
39
 * Web hosting (ex: for your blog) via "Apache":https://www.apache.org/.
40
 * Firewall management via "ferm":http://ferm.foo-projects.org/.
40
 * Firewall management via "ferm":http://ferm.foo-projects.org/.
41
 * Intrusion prevention via "fail2ban":http://www.fail2ban.org/ and rootkit detection via "rkhunter":http://rkhunter.sourceforge.net.
41
 * Intrusion prevention via "fail2ban":http://www.fail2ban.org/ and rootkit detection via "rkhunter":http://rkhunter.sourceforge.net.
42
+* SSH configuration preventing root login and insecure password authentication
42
 * Nightly backups to "Tarsnap":https://www.tarsnap.com/.
43
 * Nightly backups to "Tarsnap":https://www.tarsnap.com/.
43
 * A bunch of nice-to-have tools like "mosh":http://mosh.mit.edu and "htop":http://htop.sourceforge.net that make life with a server a little easier.
44
 * A bunch of nice-to-have tools like "mosh":http://mosh.mit.edu and "htop":http://htop.sourceforge.net that make life with a server a little easier.
44
 
45
 
65
 # Put your SSL certificate's components in the respective files that start with @wildcard_ca@ in @roles/common/files@, and a combined version in @roles/ircbouncer/files/etc_ssl_znc-combined.pem@.
66
 # Put your SSL certificate's components in the respective files that start with @wildcard_ca@ in @roles/common/files@, and a combined version in @roles/ircbouncer/files/etc_ssl_znc-combined.pem@.
66
 # Set up SPF and reverse DNS "as per the inspirational post":http://sealedabstract.com/code/nsa-proof-your-e-mail-in-2-hours/. Make sure to validate that it's all working, for example by sending an email to <a href="mailto:check-auth@verifier.port25.com">check-auth@verifier.port25.com</a> and reviewing the report that will be emailed back to you.
67
 # Set up SPF and reverse DNS "as per the inspirational post":http://sealedabstract.com/code/nsa-proof-your-e-mail-in-2-hours/. Make sure to validate that it's all working, for example by sending an email to <a href="mailto:check-auth@verifier.port25.com">check-auth@verifier.port25.com</a> and reviewing the report that will be emailed back to you.
67
 # Sign in to the ZNC web interface and set things up to your liking.
68
 # Sign in to the ZNC web interface and set things up to your liking.
68
-# You should probably disable remote root login and password-based logins in @/etc/ssh/sshd_config@ but that's up to you.
69
 
69
 
70
 Now, the time-consuming part: grep through the files for the string @TODO@ and replace as necessary. You'll probably want to check out all the files in the respective @vars/@ sub-directories in each playbook directory.
70
 Now, the time-consuming part: grep through the files for the string @TODO@ and replace as necessary. You'll probably want to check out all the files in the respective @vars/@ sub-directories in each playbook directory.
71
 
71
 

+ 3
- 0
roles/common/handlers/main.yml 查看文件

10
 - name: restart fail2ban
10
 - name: restart fail2ban
11
   service: name=fail2ban state=restarted
11
   service: name=fail2ban state=restarted
12
 
12
 
13
+- name: restart sshd
14
+  service: name=ssh state=restarted
15
+
13
 - include: ferm.yml
16
 - include: ferm.yml

+ 5
- 0
roles/common/tasks/security.yml 查看文件

9
   copy: src=etc_fail2ban_filter.d_dovecot-pop3imap.conf dest=/etc/fail2ban/filter.d/dovecot-pop3imap.conf
9
   copy: src=etc_fail2ban_filter.d_dovecot-pop3imap.conf dest=/etc/fail2ban/filter.d/dovecot-pop3imap.conf
10
 - template: src=etc_fail2ban_jail.local.j2 dest=/etc/fail2ban/jail.local
10
 - template: src=etc_fail2ban_jail.local.j2 dest=/etc/fail2ban/jail.local
11
   notify: restart fail2ban
11
   notify: restart fail2ban
12
+
13
+- name: Copy sshd_config into place
14
+  template: src=etc_ssh_sshd_config.j2 dest=/etc/ssh/sshd_config
15
+  notify: restart ssh
16
+

+ 87
- 0
roles/common/templates/etc_ssh_sshd_config.j2 查看文件

1
+# Package generated configuration file
2
+# See the sshd_config(5) manpage for details
3
+
4
+# What ports, IPs and protocols we listen for
5
+Port 22
6
+# Use these options to restrict which interfaces/protocols sshd will bind to
7
+#ListenAddress ::
8
+#ListenAddress 0.0.0.0
9
+Protocol 2
10
+# HostKeys for protocol version 2
11
+HostKey /etc/ssh/ssh_host_rsa_key
12
+HostKey /etc/ssh/ssh_host_dsa_key
13
+HostKey /etc/ssh/ssh_host_ecdsa_key
14
+#Privilege Separation is turned on for security
15
+UsePrivilegeSeparation yes
16
+
17
+# Lifetime and size of ephemeral version 1 server key
18
+KeyRegenerationInterval 3600
19
+ServerKeyBits 768
20
+
21
+# Logging
22
+SyslogFacility AUTH
23
+LogLevel INFO
24
+
25
+# Authentication:
26
+LoginGraceTime 120
27
+PermitRootLogin no
28
+StrictModes yes
29
+
30
+RSAAuthentication yes
31
+PubkeyAuthentication yes
32
+#AuthorizedKeysFile	%h/.ssh/authorized_keys
33
+
34
+# Don't read the user's ~/.rhosts and ~/.shosts files
35
+IgnoreRhosts yes
36
+# For this to work you will also need host keys in /etc/ssh_known_hosts
37
+RhostsRSAAuthentication no
38
+# similar for protocol version 2
39
+HostbasedAuthentication no
40
+# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
41
+#IgnoreUserKnownHosts yes
42
+
43
+# To enable empty passwords, change to yes (NOT RECOMMENDED)
44
+PermitEmptyPasswords no
45
+
46
+# Change to yes to enable challenge-response passwords (beware issues with
47
+# some PAM modules and threads)
48
+ChallengeResponseAuthentication no
49
+
50
+# Change to no to disable tunnelled clear text passwords
51
+PasswordAuthentication no
52
+
53
+# Kerberos options
54
+#KerberosAuthentication no
55
+#KerberosGetAFSToken no
56
+#KerberosOrLocalPasswd yes
57
+#KerberosTicketCleanup yes
58
+
59
+# GSSAPI options
60
+#GSSAPIAuthentication no
61
+#GSSAPICleanupCredentials yes
62
+
63
+X11Forwarding yes
64
+X11DisplayOffset 10
65
+PrintMotd no
66
+PrintLastLog yes
67
+TCPKeepAlive yes
68
+#UseLogin no
69
+
70
+#MaxStartups 10:30:60
71
+#Banner /etc/issue.net
72
+
73
+# Allow client to pass locale environment variables
74
+AcceptEnv LANG LC_*
75
+
76
+Subsystem sftp /usr/lib/openssh/sftp-server
77
+
78
+# Set this to 'yes' to enable PAM authentication, account processing,
79
+# and session processing. If this is enabled, PAM authentication will
80
+# be allowed through the ChallengeResponseAuthentication and
81
+# PasswordAuthentication.  Depending on your PAM configuration,
82
+# PAM authentication via ChallengeResponseAuthentication may bypass
83
+# the setting of "PermitRootLogin without-password".
84
+# If you just want the PAM account and session checks to run without
85
+# PAM authentication, then enable this but set PasswordAuthentication
86
+# and ChallengeResponseAuthentication to 'no'.
87
+UsePAM yes

正在加载...
取消
保存