diff --git a/templates/ssh/sshd_config.erb b/templates/ssh/sshd_config.erb
index 373a136441733c8a477d8366655f66538c975ec5..78b784fa82bedb432aff095dd46f29e6f388561a 100644
--- a/templates/ssh/sshd_config.erb
+++ b/templates/ssh/sshd_config.erb
@@ -4,6 +4,17 @@
 # GSS-API.  It will eventually become the default.  The default configuration
 # values that we don't change are omitted from this file.
 
+<%
+  if (listen_addresses != 'all')
+    # Split the addresses at the commas.
+    addresses = listen_addresses.split(',')
+    addresses.each do |address|
+-%>
+ListenAddress <%= address %>
+<%
+    end
+  end
+-%>
 Port 22
 Protocol 2
 <% if operatingsystem == 'RedHat' then -%>
@@ -79,14 +90,3 @@ Subsystem sftp /usr/lib/openssh/sftp-server
 Match User gitolite
     ForceCommand /usr/share/gitolite/gitolite-wrapper
 <% end -%>
-<%
-  if (listen_addresses != 'all')
-    # Split the addresses at the commas.
-    addresses = listen_addresses.split(',')
-    addresses.each do |address|
--%>
-ListenAddress <%= address %>
-<%
-    end
-  end
--%>