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

User Logins and Accounts

When a login occurs, the SSH server can take special actions. Here, we discuss:

  • Printing welcome messages for the user

  • Setting environment variables

  • Taking arbitrary actions with initialization scripts

5.6.1 Welcome Messages for the User

sshd can display custom messages for the user before and after authentication. Before authentication, the SSH server can optionally display the contents of any file you select with the Banner keyword (OpenSSH) or BannerMessageFile keyword (Tectia):

    # OpenSSH
    Banner /usr/local/etc/warning.txt

    # Tectia
    BannerMessageFile  /usr/local/etc/warning.txt

By default, OpenSSH displays no banner message, whereas Tectia displays the contents of /etc/ssh2/ssh_banner_message if the file exists.[76] The banner message is often used for legal statements that forbid unauthorized access. Since the file is sent before authentication, be careful that it doesn’t reveal sensitive information.

After authentication, both OpenSSH’s and Tectia’s sshd optionally prints the standard Unix “message of the day” file ( /etc/motd ). This output may be turned on and off with the PrintMotd keyword with the value yes (the default) or no:

    PrintMotd no

Since most Unix shells print /etc/motd on login, this SSH feature is often redundant and turned off.

For Tectia, a message about email (e.g., “You have mail”) is printed on login if the CheckMail keyword has the value of yes (the default), or the message is skipped if the value is no:

    # Tectia
    CheckMail yes

In OpenSSH, the last login time is also printed if the PrintLastLog keyword has the value of yes (the default), or the message is skipped if the value is no:

 # OpenSSH
    PrintLastLog yes

Tectia has no separate keyword to control printing the last login time—it’s always printed, if available.

The SSH server also obeys the Unix hushlogin convention, which allows each user to control whether these welcome messages are printed. If the file ~/.hushlogin exists, then the message of the day, the mail notification message (for Tectia), and the last login time are all omitted.

5.6.2 Setting Environment Variables

As we’ll see later, SSH clients have several ways to set environment variables in the server before the login shell is invoked,[77] such as the environment file [7.1.3], the SendEnv (OpenSSH) or SetRemoteEnv (Tectia) configuration keywords [7.4.4.3], and the environment option in the authorized_keys (OpenSSH) or authorization (Tectia) file [8.2.5]. However, these changes happen only with the server’s permission; otherwise, SSH clients could circumvent server security policies.

The OpenSSH server grants or denies permission for clients to modify the environment in this manner, using the PermitUserEnvironment and AcceptEnv keywords. PermitUserEnvironment controls whether the server pays attention to the user’s ~/.ssh/environment file and authorized_keys files, with a value of yes or no (the default):

    # OpenSSH
    PermitUserEnvironment yes

AcceptEnv controls how the server accepts or rejects environment variables that are sent from the SSH client according to the SendEnv (OpenSSH) or SetRemoteEnv (Tectia) keywords. Normally the SSH server pays no attention to such environment variables, but you can use the AcceptEnv keyword to allow specific variables to be copied, with their values, into SSH sessions on the server machine.

The AcceptEnv keyword lists the environment variables that are accepted, either separated by whitespace or specified by multiple keywords. Wildcard characters * and ? will match classes of environment variables.

    # OpenSSH
    AcceptEnv LANG LC_*
    AcceptEnv PATH TERM TZ

Likewise, the Tectia SSH server permits or denies permission for clients to modify the environment prior to login. Its SettableEnvironmentVars keyword lists environment variables that can be set by any of the methods, separated by commas (and optional whitespace), or specified by multiple keywords. The environment variables are matched against patterns. [11.6.1]

    # Tectia
    SettableEnvironmentVars LANG,LC_(ALL|COLLATE|CTYPE|MONETARY|NUMERIC|TIME)
    SettableEnvironmentVars PATH, TERM, TZ

The SettableEnvironmentVars keyword applies only to user-configurable environment variables. Files like /etc/environment controlled by the server administrator are not affected.

In all these cases, users are still free to set any environment variables after their login shells are invoked. The restrictions apply only to the mechanisms for initializing the environment of the login shell.

5.6.3 Initialization Scripts

When a user logs in, her Unix shell runs one or more initialization scripts , such as /etc/profile. In addition, sshd runs the script /etc/ssh/sshrc (OpenSSH) or /etc/ssh2/sshrc (Tectia) for each SSH-based login. This feature lets the system administrator run special commands for SSH logins that don’t occur for ordinary logins. For example, you can do some additional logging of SSH connections, print welcome messages for SSH users only, etc.

The /etc/ssh/sshrc or /etc/ssh2/sshrc script is always processed by the Bourne shell ( /bin/sh), rather than the user’s shell, so it can run reliably for all accounts regardless of their various shells. It is run for logins (e.g., ssh my-host) and remote commands (ssh my-host /bin/who), just before the user’s shell or command is invoked but after environment variables are initialized. The script runs in a separate shell, which exits after the script finishes, so it cannot initialize environment variables for the session. The script runs under the target account’s uid, so it can’t take privileged actions. If the script exits due to an error (say, a syntax error), the SSH session continues normally.

Note that this file is run as input to the Bourne shell: sshd runs /bin/sh /etc/ssh/sshrc, not /bin/sh -c /etc/ssh/sshrc. This means that it can’t be an arbitrary program; it must be a file containing Bourne-shell commands (and it doesn’t need the execute mode bit set).

/etc/ssh/sshrc or /etc/ssh2/sshrc operates machinewide: it is run for every incoming SSH connection. For more fine-grained control, users may create the script ~/.ssh/rc (OpenSSH) or ~/.ssh2/rc (Tectia) to be run instead of the machinewide script /etc/ssh/sshrc or /etc/ssh2/sshrc, respectively. [8.4] The machinewide script isn’t executed if the user-specific script exists in the target account, but a user script can run the machinewide script directly. OpenSSH always runs ~/.ssh/rc using the Bourne shell (like /etc/ssh/sshrc), but Tectia runs ~/.ssh2/rc using each user’s shell (in contrast to /etc/ssh2/sshrc). OpenSSH ignores user scripts if a subsystem is used, but Tectia does not. [5.8]

Note that SSH rc files interact with X authentication. [9.4.5.2]



[76] SSH clients are not required (by the SSH-2 protocol) to display the message.

[77] And also before the user rc script, ~/.ssh/rc (OpenSSH) or ~/.ssh2/rc (Tectia). [5.6.3]