Table of Contents for
SSH, The Secure Shell: The Definitive Guide, 2nd Edition

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition SSH, The Secure Shell: The Definitive Guide, 2nd Edition by Robert G. Byrnes Published by O'Reilly Media, Inc., 2005
  1. Cover
  2. SSH, the Secure Shell, 2nd Edition
  3. Preface
  4. Protect Your Network with SSH
  5. Intended Audience
  6. Reading This Book
  7. Our Approach
  8. Which Chapters Are for You?
  9. Supported Platforms
  10. Disclaimers
  11. Conventions Used in This Book
  12. Comments and Questions
  13. Safari Enabled
  14. Acknowledgments
  15. 1. Introduction to SSH
  16. What Is SSH?
  17. What SSH Is Not
  18. The SSH Protocol
  19. Overview of SSH Features
  20. History of SSH
  21. Related Technologies
  22. Summary
  23. 2. Basic Client Use
  24. A Running Example
  25. Remote Terminal Sessions with ssh
  26. Adding Complexity to the Example
  27. Authentication by Cryptographic Key
  28. The SSH Agent
  29. Connecting Without a Password or Passphrase
  30. Miscellaneous Clients
  31. Summary
  32. 3. Inside SSH
  33. Overview of Features
  34. A Cryptography Primer
  35. The Architecture of an SSH System
  36. Inside SSH-2
  37. Inside SSH-1
  38. Implementation Issues
  39. SSH and File Transfers (scp and sftp)
  40. Algorithms Used by SSH
  41. Threats SSH Can Counter
  42. Threats SSH Doesn’t Prevent
  43. Threats Caused by SSH
  44. Summary
  45. 4. Installation and Compile-Time Configuration
  46. Overview
  47. Installing OpenSSH
  48. Installing Tectia
  49. Software Inventory
  50. Replacing r-Commands with SSH
  51. Summary
  52. 5. Serverwide Configuration
  53. Running the Server
  54. Server Configuration: An Overview
  55. Getting Ready: Initial Setup
  56. Authentication: Verifying Identities
  57. Access Control: Letting People In
  58. User Logins and Accounts
  59. Forwarding
  60. Subsystems
  61. Logging and Debugging
  62. Compatibility Between SSH-1 and SSH-2 Servers
  63. Summary
  64. 6. Key Management and Agents
  65. What Is an Identity?
  66. Creating an Identity
  67. SSH Agents
  68. Multiple Identities
  69. PGP Authentication in Tectia
  70. Tectia External Keys
  71. Summary
  72. 7. Advanced Client Use
  73. How to Configure Clients
  74. Precedence
  75. Introduction to Verbose Mode
  76. Client Configuration in Depth
  77. Secure Copy with scp
  78. Secure, Interactive Copy with sftp
  79. Summary
  80. 8. Per-Account Server Configuration
  81. Limits of This Technique
  82. Public-Key-Based Configuration
  83. Hostbased Access Control
  84. The User rc File
  85. Summary
  86. 9. Port Forwarding and X Forwarding
  87. What Is Forwarding?
  88. Port Forwarding
  89. Dynamic Port Forwarding
  90. X Forwarding
  91. Forwarding Security: TCP-Wrappers and libwrap
  92. Summary
  93. 10. A Recommended Setup
  94. The Basics
  95. Compile-Time Configuration
  96. Serverwide Configuration
  97. Per-Account Configuration
  98. Key Management
  99. Client Configuration
  100. Remote Home Directories (NFS, AFS)
  101. Summary
  102. 11. Case Studies
  103. Unattended SSH: Batch or cron Jobs
  104. FTP and SSH
  105. Pine, IMAP, and SSH
  106. Connecting Through a Gateway Host
  107. Scalable Authentication for SSH
  108. Tectia Extensions to Server Configuration Files
  109. Tectia Plugins
  110. 12. Troubleshooting and FAQ
  111. Debug Messages: Your First Line of Defense
  112. Problems and Solutions
  113. Other SSH Resources
  114. 13. Overview of Other Implementations
  115. Common Features
  116. Covered Products
  117. Other SSH Products
  118. 14. OpenSSH for Windows
  119. Installation
  120. Using the SSH Clients
  121. Setting Up the SSH Server
  122. Public-Key Authentication
  123. Troubleshooting
  124. Summary
  125. 15. OpenSSH for Macintosh
  126. Using the SSH Clients
  127. Using the OpenSSH Server
  128. 16. Tectia for Windows
  129. Obtaining and Installing
  130. Basic Client Use
  131. Key Management
  132. Accession Lite
  133. Advanced Client Use
  134. Port Forwarding
  135. Connector
  136. File Transfers
  137. Command-Line Programs
  138. Troubleshooting
  139. Server
  140. 17. SecureCRT and SecureFX for Windows
  141. Obtaining and Installing
  142. Basic Client Use
  143. Key Management
  144. Advanced Client Use
  145. Forwarding
  146. Command-Line Client Programs
  147. File Transfer
  148. Troubleshooting
  149. VShell
  150. Summary
  151. 18. PuTTY for Windows
  152. Obtaining and Installing
  153. Basic Client Use
  154. File Transfer
  155. Key Management
  156. Advanced Client Use
  157. Forwarding
  158. Summary
  159. A. OpenSSH 4.0 New Features
  160. Server Features: sshd
  161. Client Features: ssh, scp, and sftp
  162. ssh-keygen
  163. B. Tectia Manpage for sshregex
  164. Regex Syntax: Egrep Patterns
  165. Regex Syntax: ZSH_FILEGLOB (or Traditional) Patterns
  166. Character Sets for Egrep and ZSH_FILEGLOB
  167. Regex Syntax: SSH Patterns
  168. Authors
  169. See Also
  170. C. Tectia Module Names for Debugging
  171. D. SSH-1 Features of OpenSSH and Tectia
  172. OpenSSH Features
  173. Tectia Features
  174. E. SSH Quick Reference
  175. Legend
  176. sshd Options
  177. sshd Keywords
  178. ssh Options
  179. scp Options
  180. ssh and scp Keywords
  181. ssh-keygen Options
  182. ssh-agent Options
  183. ssh-add Options
  184. Identity and Authorization Files, OpenSSH
  185. Identity and Authorization Files, Tectia
  186. Environment Variables
  187. Index
  188. Index
  189. Index
  190. Index
  191. Index
  192. Index
  193. Index
  194. Index
  195. Index
  196. Index
  197. Index
  198. Index
  199. Index
  200. Index
  201. Index
  202. Index
  203. Index
  204. Index
  205. Index
  206. Index
  207. Index
  208. Index
  209. Index
  210. Index
  211. Index
  212. Index
  213. About the Authors
  214. Colophon
  215. Copyright

Serverwide Configuration

Chapter 5 provided a detailed discussion of sshd and how to configure its runtime behavior. Now let’s determine which configuration options are most important for security.

10.3.1 Disable Other Means of Access

SSH can provide a secure front door into your system, but don’t forget to close the back doors. If your system allows access via the infamous r-commands, disable them. This means:

  • Remove the file /etc/hosts.equiv, or make it a read-only empty file.

  • Disable rshd, rlogind, and rexecd by removing or commenting out their lines in the inetd or xinetd configuration file. For example, in /etc/inetd.conf you might do:

        # turned off -- don't use!
        #shell   stream  tcp   nowait  root  /usr/sbin/in.rshd     in.rshd

    Make sure you restart inetd or xinetd after doing this so that the change takes effect.

  • Educate users not to create .rhosts files.

You might also consider disabling telnetd and other insecure avenues for logging in, permitting logins only via SSH.

10.3.2 sshd_config for OpenSSH

We’ll now discuss our recommended sshd_config settings for OpenSSH. We have omitted some keywords that aren’t particularly security-related, such as PrintMotd, which simply prints a message after login. For any remaining keywords, use your judgment based on your system and needs.

10.3.2.1 Choice of protocol

We recommend disabling the SSH-1 protocol altogether:

    # OpenSSH
    Protocol 2

10.3.2.2 Important files

Important files containing your host key, PID, and so on, may be located anywhere on the machine’s local disk. For security’s sake, don’t put them on an NFS-mounted partition. If you do, each time the files are accessed by the SSH server, their contents are transmitted in the clear over the network.

    # OpenSSH
    HostKey /etc/ssh/ssh_host_key
    PidFile /var/run/sshd.pid

10.3.2.3 File and directory permissions

The StrictModes value requires users to protect their SSH-related files and directories, or else they can’t authenticate.

    # OpenSSH
    StrictModes yes

10.3.2.4 TCP/IP settings

The Port and ListenAddress values we recommend are standard. Also, we enable keepalive messages so that connections to clients that have crashed or otherwise become unreachable will terminate rather than hang around and require manual reaping by the sysadmin.

    # OpenSSH
    Port 22
    ListenAddress 0.0.0.0
    TcpKeepAlive yes

We also disable reverse DNS lookups on incoming connections:

    # OpenSSH
    UseDNS no

You might think security is increased by reverse DNS lookups, but in fact, DNS isn’t secure enough to guarantee accurate lookups. Also, due to other issues in your Unix and network environment, reverse DNS mappings might not even work properly. [5.3.3.8] Finally, SSH connections can be tremendously slowed down or fail altogether if the client’s DNS is hosed (e.g., lots of nameservers, all unresponsive, so sshd times out). The IP addresses of connecting hosts end up in your logs anyway, so you can look them up later.

10.3.2.5 Login time

For logins we allow 30 seconds for a successful authentication, which should be long enough for users and automated processes:

    # OpenSSH
    LoginGraceTime 30

10.3.2.6 Authentication

We enable only public-key authentication. Password authentication is disabled because passwords can be stolen and used more easily than public keys. This is a fairly harsh restriction, so you might want to leave it enabled depending on your needs. Without password authentication, you have a “chicken and egg” problem: how do users upload their public keys securely the first time? As system administrator, you have to institute a process for this transfer: for example, users can generate keys on a client machine and then request that you install them on the server machine. Rhosts authentication is disabled because it can be spoofed. RhostsRSA authentication is disabled too, because overall it is a medium-security method and this configuration is on the side of higher security.

    # OpenSSH
    PubkeyAuthentication yes

    PasswordAuthentication no
    PermitEmptyPasswords no               Already disabled, but we're being paranoid
    RSAAuthentication no
    RhostsRSAAuthentication no
    HostbasedAuthentication no
    KerberosAuthentication no             Optional
    ChallengeResponseAuthentication no    Optional
    GSSAPIAuthentication no               Optional

We optionally disable Kerberos, keyboard-interactive, and GSSAPI authentication, even though they are quite secure, under the “keep it simple” principle: disable what you aren’t using. Most SSH users aren’t set up to use these techniques. Reenable them if your server needs to support them.

Although we’ve disabled hostbased authentication already, we still forbid sshd to use .rhosts files at all (just in case you reenable hostbased authentication):

    # OpenSSH
    IgnoreRhosts yes
    IgnoreRootRhosts yes

10.3.2.7 Access control

If you want to restrict access to particular local accounts or Unix groups, add AllowUsers and AllowGroups lines (or DenyUsers and DenyGroups). We recommend creating a group for all your system’s SSH users, called “ssh”, and configuring the server with:

    AllowGroups ssh

Now you’ve made SSH access a specific privilege to be granted or revoked, and you can easily do it for a user without changing the sshd configuration:

    # usermod -G ssh,... joe         Add user joe to the SSH group

As a bonus, you’ve disallowed SSH access by system accounts like bin, sys, and daemon that should never use SSH anyway.

We also permit the superuser to connect via SSH but not by password authentication. This is redundant but consistent with turning off PasswordAuthentication.

    # OpenSSH
    PermitRootLogin without-password

10.3.2.8 Forwarding

We permit TCP port forwarding and X forwarding so that users can secure their other TCP connections:

    # OpenSSH
    AllowTcpForwarding yes
    X11Forwarding yes

10.3.2.9 SFTP

Confirm that the SFTP subsystem is defined so that incoming sftp connections will work. (It is enabled in the default /etc/ssh/sshd_config file for OpenSSH.)

    # OpenSSH
    Subsystem    sftp    /usr/lib/ssh/sftp-server

10.3.3 sshd2_config for Tectia

We now move to our recommended sshd2_config settings for Tectia. Again, we’ve omitted some keywords that are not security-related.

10.3.3.1 Choice of protocol

We recommend disabling the SSH-1 protocol altogether:

    # Tectia
    Ssh1Compatibility no
    Sshd1Path /dev/null      Not strictly necessary, just our paranoia

10.3.3.2 Important files

As we have mentioned for OpenSSH [10.3.2.2], make sure all SSH-related files are on local disks, not remotely mounted partitions:

    # Tectia
    HostKeyFile /etc/ssh2/hostkey
    PublicHostKeyFile /etc/ssh2/hostkey.pub
    RandomSeedFile /etc/ssh2/random_seed

For the following settings, consider the pros and cons of storing user files on NFS-mounted filesystems: [10.7]

    # Tectia
    UserConfigDirectory directory
    IdentityFile filename
    AuthorizationFile filename

10.3.3.3 File and directory permissions

The StrictModes value requires users to protect their SSH-related files and directories, or else they can’t authenticate:

    # Tectia
    StrictModes yes

10.3.3.4 TCP/IP settings

We recommend the same configuration as for OpenSSH, for the same reasons: [10.3.2.4]

    # Tectia
    Port 22

    ListenAddress 0.0.0.0
    KeepAlive yes
    RequireReverseMapping no

10.3.3.5 Login time

For logins we allow 30 seconds for a successful authentication, which should be long enough for users and automated processes:

    # Tectia
    LoginGraceTime 30

10.3.3.6 Authentication

These settings mirror those for OpenSSH:

    # Tectia
    AllowedAuthentications publickey
    RequiredAuthentications publickey          Overrides AllowedAuthentications; we're being paranoid
    PermitEmptyPasswords no                    Already disabled, but we're being paranoid

Although we’ve disabled hostbased authentication already, we still forbid sshd to use .rhosts files at all (just in case you reenable hostbased authentication). We also disable UserKnownHosts to prevent users from extending trust to unknown hosts for the purpose of hostbased authentication. The superuser can still specify trusted hosts in /etc/ssh2/knownhosts.

    # Tectia
    IgnoreRhosts yes
    IgnoreRootRhosts yes
    UserKnownHosts no

10.3.3.7 Access control

We permit SSH connections only from within the local domain[140]:

    # Tectia
    AllowHosts fred@* *.your.domain.com        Just an example

except for the account fred in this example, which may receive connections from anywhere.

If you want to restrict access to particular local accounts or Unix groups, add AllowUsers and AllowGroups lines (or DenyUsers and DenyGroups ). Also create an “ssh” group as we described earlier. [10.3.2.7]

We permit the superuser to connect via SSH but not by password authentication. This is redundant but consistent with turning off PasswordAuthentication.

    # Tectia
    PermitRootLogin nopwd

10.3.3.8 Forwarding

We permit TCP port forwarding and X forwarding so that users can secure their other TCP connections:

    # Tectia
    AllowTcpForwarding yes
    X11Forwarding yes

10.3.3.9 Encryption

Use either of the following settings as fits your needs. The notable feature is that they both exclude the “none” cipher which may be a security risk.

    # Tectia
    Ciphers anycipher
    Ciphers anystdcipher

10.3.3.10 SFTP

Confirm that the SFTP subsystem is defined so that incoming sftp connections will work. (It is enabled in the default /etc/ssh2/sshd2_config for Tectia.)

    # Tectia
    subsystem-sftp   sftp-server


[140] The reliability of this restriction depends on the integrity of DNS. Unfortunately, due to the implementation of AllowHosts, restriction by IP address is no more secure. [5.5.1]