Skip to content
Snippets Groups Projects
sshd_config.erb 3.92 KiB
Newer Older
Adam Lewenberg's avatar
Adam Lewenberg committed
# sshd server configuration file, allowing root.  -*- conf -*-
#
# This sshd configuration permits root logins provided that they're done via
# GSS-API.  It will eventually become the default.  The default configuration
# values that we don't change are omitted from this file.

<%-
  # Split the ports at the commas.
  ports = @listen_ports.split(',')
  ports.each do |port|
-%>
Port <%= port %>
  if (@listen_addresses != 'all')
    # Split the addresses at the commas.
    addresses = @listen_addresses.split(',')
    addresses.each do |address|
-%>
ListenAddress <%= address %>
# Only support protocol version 2.
Adam Lewenberg's avatar
Adam Lewenberg committed
Protocol 2

# Only support RSA keys, not DSA keys.
HostKey /etc/ssh/ssh_host_rsa_key

Adam Lewenberg's avatar
Adam Lewenberg committed
<% if @ed25519 then -%>
# Also support Ed25519 host keys.
HostKey /etc/ssh/ssh_host_ed25519_key

<% end -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
# Increase the login grace period from 120 seconds to 300 seconds (5 minutes).
LoginGraceTime 300

# Prevent attackers from running long password guessing attacks.
MaxAuthTries <%= @max_tries %>
<% if @osfamily == 'RedHat' then -%>
# Some Red Hat systems are old enough that this has to be explicitly enabled.
UsePrivilegeSeparation yes

<% end -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
# Disable all forms of host-based and public key authentication by default,
# since we use GSS-API (or passwords).
IgnoreRhosts yes
RSAAuthentication no
PubkeyAuthentication <%= @pubkey ? 'yes' : 'no' %>
Adam Lewenberg's avatar
Adam Lewenberg committed
RhostsRSAAuthentication no
HostbasedAuthentication <%= @hostbased ? 'yes' : 'no' %>
Adam Lewenberg's avatar
Adam Lewenberg committed

# Allow password authentication via PAM, but not empty passwords.
ChallengeResponseAuthentication yes
Adam Lewenberg's avatar
Adam Lewenberg committed
PasswordAuthentication <%= @password ? 'yes' : 'no' %>
Adam Lewenberg's avatar
Adam Lewenberg committed
UsePAM yes
PermitEmptyPasswords no

# Enable GSS-API authentication.  Eventually (squeeze and later) we will want
# to add GSSAPIStoreCredentialsOnRekey yes.
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
Adam Lewenberg's avatar
Adam Lewenberg committed
<% if (@osfamily != 'RedHat') or (@lsbmajdistrelease.to_i() >= 6) then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
GSSAPIKeyExchange yes
GSSAPIStrictAcceptorCheck no
<% end -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
<% if (@operatingsystem == 'Debian') and (@lsbdistcodename != 'lenny') then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
GSSAPIStoreCredentialsOnRekey yes
<% end -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
<% if (@osfamily == 'RedHat') and (@lsbmajdistrelease.to_i() >= 6) then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
GSSAPIStoreCredentialsOnRekey yes
<% end -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
<% if (@operatingsystem == 'Ubuntu') then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
GSSAPIStoreCredentialsOnRekey yes
<% end -%>
<% if (@pam_duo) then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed

# Require both (GSS-API|PASSWORD) and PAM.
Adam Lewenberg's avatar
Adam Lewenberg committed
AuthenticationMethods gssapi-with-mic,keyboard-interactive:pam<% if @password then %> password,keyboard-interactive:pam<% end %>
KerberosAuthentication yes
<% end -%>
<%- if (@rootloginwithpswd == 'yes') -%>
# Allow root login with a password (use with care!)
PermitRootLogin yes
<% else -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
# Allow root login, but only if no password was used (meaning GSS-API).
PermitRootLogin without-password
Adam Lewenberg's avatar
Adam Lewenberg committed

# Allow X forwarding.
X11Forwarding yes
X11DisplayOffset 10

<% if @osfamily != 'RedHat' then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
# Disable printing of the MOTD, since this is done via other means on Debian.
PrintMotd no

Adam Lewenberg's avatar
Adam Lewenberg committed
# Send TCP keep-alive messages to keep the connection open through firewalls
# and notice connection termination.
TCPKeepAlive yes

# Enable sftp.
<% if @osfamily == 'RedHat' then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed
Subsystem sftp /usr/libexec/openssh/sftp-server
<% else -%>
Subsystem sftp /usr/lib/openssh/sftp-server
<% end -%>
<% if @gitolite then -%>
Adam Lewenberg's avatar
Adam Lewenberg committed

# gitolite user should run through a wrapper to map it to actual user.
Match User gitolite
    ForceCommand /usr/share/gitolite/gitolite-wrapper
<% end -%>
<%- if (@max_sessions != 'NOT DEFINED') then -%>

<%-   if (@max_sessions <= 10) then -%>
# Allow fewer sessions
<%-   else -%>
# Allow more sessions
<%-   end -%>
MaxSessions <%= @max_sessions %>
<%- end -%>
<% if (@pam_duo) and (@rootloginwithpswd == 'no') then -%>

# Because we are enabling Duo but root logins cannot use Duo (yet),
# we have to configure the authentications for root separately.
Match User root,root.*,*.root,admin.*,*.admin
  AuthenticationMethods gssapi-with-mic
  MaxSessions 3
<% end -%>