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

Forwarding

Forwarding (or tunneling) is the use of SSH to protect another network service. We discuss it in detail in Chapter 9, but here we describe the available serverwide configuration options.

5.7.1 Port Forwarding

SSH’s forwarding (or tunneling) features protect other TCP/IP-based applications by encrypting their connections. We cover forwarding in great detail in Chapter 9, but we introduce here the serverwide configuration keywords for controlling it.

TCP port forwarding can be enabled or disabled by the keyword AllowTcpForwarding, with the value yes (the default) or no:

    AllowTcpForwarding no

Tectia can specify this more selectively for particular users or Unix groups, with the keywords AllowTcpForwardingForUsers, AllowTcpForwardingForGroups, DenyTcpForwardingForUsers, and DenyTcpForwardingForGroups:

    # Tectia
    AllowTcpForwardingForUsers smith
    AllowTcpForwardingForGroups students
    DenyTcpForwardingForUsers evildoer
    DenyTcpForwardingForGroups badguys

The values for these keywords use the same syntax as for AllowUsers, AllowGroups, DenyUsers, and DenyGroups, respectively: [5.5.1] [5.5.2]

    # Tectia with zsh_fileglob or traditional regex syntax
    AllowTcpForwardingForUsers good*@*.friendly.org,*@\i10.1.2.*,12[[:digit:]]
    DenyTcpForwardingForGroups bad*,33[[:digit:]]

    # Tectia with egrep regex syntax
    AllowTcpForwardingForUsers good.*@.*\.friendly\.org,.*@\i10\.1\.2\.*,12[[:digit:]]
    DenyTcpForwardingForGroups bad.*,33[[:digit:]]

Tectia’s ForwardACL keyword provides the most precise access control for specific forwardings.[78] Its use is complicated but it provides great flexibility. It uses multiple values (separated by whitespace), with the general format:

    # Tectia
    ForwardACL access direction client forward [originator]

The values stand for:

access

Either allow or deny, indicating the type of control to be applied.

direction

Either local or remote, specifying the kind of forwarding being controlled.[79]

client

A pattern describing the SSH client, with the same syntax as the UserSpecificConfig keyword, with the components user [% group ][@ chost ]: [11.6.2]

user

Matches the username requested by the client

group

(Optional) Matches any of the groups that claim the user as a member

chost

(Optional) Matches the machine from which the SSH connection originates, i.e., where the SSH client program runs

forward

For local forwardings, a pattern that matches the forwarding target, where the application server runs, as shown in Figure 5-3, which illustrates the result of running the command:[80]

    chost$ ssh -L[faddr:]fport:thost:tport shost

The local forward value has the form thost [% tport ], where the thost component uses the same syntax as the AllowHost keyword, and matches either the hostname provided by the SSH client, or the address resulting from the hostname lookup that is performed by the SSH server for the forwarding. The optional tport is a pattern matching the numeric value of the port on which the application server is listening, and to which the SSH server connects for the forwarding. If the port is not specified, then the access control applies to all ports.

For remote forwardings, the forward value matches the address and (optionally) the port on which the SSH server listens for forwarded connections, as shown in Figure 5-4, which illustrates the result of running the command:

    chost$ ssh -R[faddr:]fport:thost:tport shost

The remote forward value uses the same syntax as for local forwardings, with the components faddr[%fport].

originator

(Optional) A pattern that matches the source address used by the application client to connect to the forwarded port, labeled ohost in Figures 5-3 and 5-4. This is most useful for remote forwarding, since the source address can be directly determined by the SSH server when it accepts the forwarded connection.

Local forwarding with the Tectia ForwardACL keyword

Figure 5-3. Local forwarding with the Tectia ForwardACL keyword

Remote forwarding with the Tectia ForwardACL keyword

Figure 5-4. Remote forwarding with the Tectia ForwardACL keyword

For local forwarding, the SSH server must rely on the SSH client to provide the source address, and a malicious client might forge the address, so it really can’t be trusted as a basis for granting access. In addition, the source address reported by the SSH client might belong to private address space that is not meaningful to the SSH server, e.g., if network address translation (NAT) is used.

The ForwardACL keyword is one of the most complex keywords available for configuring Tectia, because so many parameters are needed to describe forwarded connections fully. The reward for conquering this complexity is precision. For example, to allow any user in the trusted group to use local forwarding when initiating SSH connections from any machine in the friendly.org domain, but only to forward IMAP connections (port 143) to the internal server mail.example.com, use:

    # Tectia with zsh_fileglob or traditional regex syntax
    ForwardACL allow local *%trusted@*.friendly.org mail.example.com%143

    # Tectia with egrep regex syntax
    ForwardACL allow local .*%trusted@.*\.friendly\.org mail\.example\.com%143

A trusted user could then run her SSH client on somewhere.friendly.org as:

    $ ssh -L2001:mail.example.com:143 ssh.example.com

where ssh.example.com is the host that runs the SSH server. Note that no restrictions are imposed on the listening port for local forwardings (2001 in this case); the SSH server has no reason to care about that, and no way to verify it anyway.

To allow guest users (i.e., those whose usernames start with “guest”) initiating SSH connections from a range of addresses described by the netmask 10.1.2.0/24 to use remote forwarding, but only listening on the localhost interface and accepting forwarded connections on a range of ports 7000-7009:

    # Tectia with zsh_fileglob or traditional regex syntax
    ForwardACL allow remote guest*@\m10.1.2.0/24 localhost:700[[:digit:]]

    # Tectia with egrep regex syntax
    ForwardACL allow remote guest.*@\m10.1.2.0/24 localhost:700[[:digit:]]

The user guest33 could then run his SSH client on a host with address 10.1.2.3 as:

    # Tectia
    $ ssh -Rlocalhost:7005:server.elsewhere.net:8080 ssh.example.com

Note that there are no restrictions on the target for the forwarding (port 8080 on server.elsewhere.net); the SSH server again neither knows nor cares about the forwarded connection on the SSH client side.

To relax this access control, allowing the SSH server to accept connections on any listening address, but only from application clients originating forwarded connections from hosts in the outbound.example.com domain, replace the localhost component in the previous forward pattern with a “match anything” wildcard, and add a fifth originator pattern:

    # Tectia with zsh_fileglob or traditional regex syntax
    ForwardACL allow remote guest*@\m10.1.2.0/24 *:700[[:digit:]] *.outbound.example.com

    # Tectia with egrep regex syntax
    ForwardACL allow remote guest.*@\m10.1.2.0/24 .*:700[[:digit:]] .*\.outbound\.example\.com

ForwardACL restrictions for local and remote forwardings are completely independent. If any ForwardACL keywords allow specific, limited access for either kind of forwarding, then all other access for that kind of forwarding will be denied.

Tectia uses the most restrictive interpretation for forwarding access control: if multiple ForwardACL keywords match a requested forwarding, and any of them deny access, then the forwarding is rejected. This can be useful for creating exceptions. For example, to allow local forwarding to any port on any target host in the example.com domain, but not to any port on the database server db.example.com, or to http servers (port 80) on any example.com hosts:

    # Tectia with zsh_fileglob or traditional regex syntax
    ForwardACL allow local  *  *.example.com
    ForwardACL deny  local  * db.example.com
    ForwardACL deny  local  *  *.example.com%80

    # Tectia with egrep regex syntax
    ForwardACL allow local .* .*\.example\.com
    ForwardACL deny  local .* db\.example\.com
    ForwardACL deny  local .* .*\.example\.com%80

Furthermore, ForwardACL keywords cannot override restrictions imposed by the other forwarding access control keywords (AllowTcpForwardingForUsers, AllowTcpForwardingForGroups, DenyTcpForwardingForUsers, DenyTcpForwardingForGroups, or AllowTcpForwarding): if any of these applicable keywords deny access for a requested forwarding, then the forwarding is forbidden.

5.7.2 X Forwarding

Forwarding for X, the popular Window System, can be separately enabled or disabled with the keyword X11Forwarding:[81]

    X11Forwarding no

OpenSSH automatically disables X11Forwarding if UseLogin is enabled. [5.4.10]

Administrators may wish to disable forwarding for users who are not trusted to have forwarding securely configured on the client side. For example, it is usually desirable to avoid SSH clients that indiscriminately accept connections from anywhere, and then forward them across SSH tunnels to trusted servers. Similarly, misconfigured X servers (which run on the SSH client side) can expose X client programs running on the SSH server side to attack, if the X server access is overly permissive.

Disabling forwarding isn’t effective for users who are granted shell access to run arbitrary commands, because such users can use their own programs to set up equivalent forwarding functionality. For better control, set up special-purpose accounts that use carefully written, restricted programs instead of standard shells, and consider using subsystems. [5.8]

5.7.3 Agent Forwarding

Agent forwarding permits a series of SSH connections (from one machine to another to another, ...) to operate seamlessly using a single agent. [6.3.5] Agent forwarding may be enabled or disabled in the Tectia server using the keyword AllowAgentForwarding with a value of yes (the default) or no:[82]

    # Tectia
    AllowAgentForwarding no

It may also be enabled or disabled by OpenSSH and Tectia clients. [6.3.5.3]

Agent forwarding is convenient, but in a security-sensitive environment, it might be appropriate to disable this feature. Because forwarded agent connections are implemented as Unix domain sockets, an attacker can conceivably gain access to them. These sockets are just nodes in the filesystem, protected only by file permissions that can be compromised.

For example, suppose you maintain a network of exposed, untrusted machines that you access from a more secure network using SSH. You might consider disabling agent forwarding on the untrusted machines. Otherwise, an attacker can compromise an untrusted machine; take control of a forwarded agent from a legitimate, incoming SSH connection; and use the agent’s loaded keys to gain access to the secure network via SSH. (The attacker can’t retrieve the keys themselves in this way, however.)



[78] ACL stands for “access control list.”

[79] These keywords are case-insensitive, but the documentation mentions only lowercase, so we recommend it.

[80] Only Tectia SSH clients allow the listening address faddr to be specified with the forwarding command-line options -L and -R.

[81] Tectia supports the keywords ForwardX11 and AllowX11Forwarding as synonyms for X11Forwarding.

[82] The keyword ForwardAgent is also supported as a synonym for backward compatibility.