A Guide To The Tcp/ip-based Network Security And Privacy Solution Covers Installation, Configuration, Maintenance, Ssh Server Control, Application Tunneling, Forced Commands, Port And Agent Forwarding, And Troubleshooting. 1. Introduction To Ssh -- 2. Basic Client Use -- 3. Inside Ssh -- 4. Installation And Compile-time Configuration -- 5. Serverwide Configuration -- 6. Key Management And Agents -- 7. Advanced Client Use -- 8. Per-account Server Configuration -- 9. Port Forwarding And X Forwarding -- 10. A Recommended Setup -- 11. Case Studies -- 12. Troubleshooting And Faq -- 13. Overview Of Other Implementations -- 14. Ssh1 Port By Sergey Okhapkin (windows) -- 15. Securecrt (windows) -- 16. F-secure Ssh Client (windows, Macintosh) -- 17. Niftytelnet Ssh (macintosh) -- A. Ssh2 Manpage For Sshregex -- B. Ssh Quick Reference. Daniel J. Barrett And Richard E. Silverman. Includes Index. Includes Bibliographical References And Index. sample.pdf -1 sterling.com -1 Welcome to Sterling Software -1 SSH, The Secure Shell - The Definitive Guide.pdf 1 Table of Content 2 Preface 7 Protect Your Network with SSH 7 Intended Audience 7 End-User Audience 7 Prerequisites 8 System-Administrator Audience 8 Prerequisites 8 Reading This Book 8 Our Approach 9 Which Chapters Are for You? 9 Supported Platforms 10 Disclaimers 10 Conventions Used in This Book 10 Comments and Questions 11 Acknowledgments 11 Chapter 1. Introduction to SSH 13 1.1 What Is SSH? 13 13 Figure 1.1. SSH architecture 13 1.2 What SSH Is Not 14 1.3 The SSH Protocol 15 15 Figure 1.2. Authentication, encryption, and integrity 15 1.3.1 Protocols, Products, Clients, and Confusion 16 1.4 Overview of SSH Features 16 1.4.1 Secure Remote Logins 17 1.4.2 Secure File Transfer 18 1.4.3 Secure Remote Command Execution 19 1.4.4 Keys and Agents 19 1.4.5 Access Control 20 1.4.6 Port Forwarding 20 1.5 History of SSH 20 1.6 Related Technologies 22 1.6.1 rsh Suite (R-Commands) 22 1.6.2 Pretty Good Privacy (PGP) 23 1.6.3 Kerberos 23 1.6.4 IPSEC 24 1.6.5 Secure Remote Password (SRP) 24 1.6.6 Secure Socket Layer (SSL) Protocol 25 1.6.7 SSL-Enhanced Telnet and FTP 25 1.6.8 stunnel 25 1.6.9 Firewalls 26 1.7 Summary 26 Chapter 2. Basic Client Use 27 2.1 A Running Example 27 2.2 Remote Terminal Sessions with ssh 27 28 Figure 2.1. Our example scenario 28 2.2.1 File Transfer with scp 28 2.3 Adding Complexity to the Example 29 2.3.1 Known Hosts 29 2.3.2 The Escape Character 31 Table 2.1. ssh Escape Sequences 31 2.4 Authentication by Cryptographic Key 32 2.4.1 A Brief Introduction to Keys 33 2.4.2 Generating Key Pairs with ssh-keygen 33 2.4.3 Installing a Public Key on an SSH ServerMachine 35 Figure 2.2. Public-key authentication 36 2.4.4 If You Change Your Key 37 2.5 The SSH Agent 37 38 Figure 2.3. How the SSH agent works 38 2.5.1 Other Uses For Agents 39 2.5.2 A More Complex Passphrase Problem 39 2.5.3 Agent Forwarding 40 Figure 2.4. How agent forwarding works 40 Figure 2.5. Third-party scp with agent forwarding 41 2.6 Connecting Without a Password or Passphrase 41 2.7 Miscellaneous Clients 42 2.7.1 sftp 42 2.7.2 slogin 43 2.7.3 Hostname Links 43 2.8 Summary 44 Chapter 3. Inside SSH 45 3.1 Overview of Features 45 3.1.1 Privacy (Encryption) 45 3.1.2 Integrity 45 3.1.3 Authentication 46 3.1.4 Authorization 47 3.1.5 Forwarding ( Tunneling) 47 3.2 A Cryptography Primer 47 3.2.1 How Secure Is Secure? 48 3.2.2 Public- and Secret-Key Cryptography 48 3.2.3 Hash Functions 49 3.3 The Architecture of an SSH System 50 50 Figure 3.1. SSH architecture 50 Table 3.1. Keys, Keys, Keys 51 3.4 Inside SSH-1 52 53 Figure 3.2. SSH-1 architecture 53 3.4.1 Establishing the Secure Connection 53 Figure 3.3. SSH-1 protocol exchange 54 3.4.2 Client Authentication 56 3.4.2.1 Password authentication 57 3.4.2.2 Public-key authentication 57 3.4.2.3 Trusted-host authentication (Rhosts and RhostsRSA) 59 3.4.2.3.1 Trusted-host access files 61 3.4.2.3.2 Control file details 61 3.4.2.3.3 Netgroups as wildcards 65 3.4.2.3.4 Summary 66 3.4.2.4 Kerberos authentication 66 Table 3.2. Kerberos Authentication Support in SSH 66 3.4.2.5 One-time passwords 67 3.4.3 Integrity Checking 68 3.4.4 Compression 68 3.5 Inside SSH-2 68 68 Figure 3.4. SSH-2 architecture 68 3.5.1 Protocol Differences (SSH-1 Versus SSH-2) 69 Figure 3.5. SSH-2 protocol family 70 3.5.1.1 Algorithm choice and negotiation 71 3.5.1.2 Session key exchange and the server key 71 3.5.1.3 Key/identity binding 72 3.5.1.4 Authentication 73 3.5.1.5 Integrity checking 73 3.5.1.6 Hostbased authentication 73 3.5.1.7 Session rekeying 74 3.5.1.8 SSH-1/SSH-2: summary 74 Table 3.3. SSH-1 and SSH-2 Differences 74 3.5.2 Implementation Differences 75 3.5.2.1 Host keys 75 3.5.2.2 No fallback to rsh 77 3.5.2.3 Setuid client 77 3.5.2.4 SSH-1 backward compatibility 78 3.6 As-User Access (userfile) 79 3.7 Randomness 79 3.8 SSH and File Transfers (scp and sftp) 81 3.8.1 scp1 Details 82 Figure 3.6. scp1 operation 82 3.8.2 scp2/sftp Details 83 Figure 3.7. scp2/sftp operation 83 3.9 Algorithms Used by SSH 84 84 Table 3.4. Algorithms in the SSH Protocols 84 Table 3.5. SSH-1 Ciphers 84 Table 3.6. SSH-2 Ciphers 84 3.9.1 Public-Key Algorithms 85 3.9.1.1 Rivest-Shamir-Adleman (RSA) 85 3.9.1.2 Digital Signature Algorithm (DSA) 85 3.9.1.3 Diffie-Hellman key agreement 86 3.9.2 Secret-Key Algorithms 86 3.9.2.1 International Data Encryption Algorithm (IDEA) 86 3.9.2.2 Data Encryption Standard (DES) 87 3.9.2.3 Triple-DES 87 3.9.2.4 ARCFOUR (RC4) 87 3.9.2.5 Blowfish 87 3.9.2.6 Twofish 88 3.9.2.7 CAST 88 3.9.2.8 Speed comparisons 88 Table 3.7. Transferring with scp2 (F-Secure SSH2 2.0.13) 88 Table 3.8. Same Test with scp1 (SSH-1.2.27) 88 3.9.3 Hash Functions 89 3.9.3.1 CRC-32 89 3.9.3.2 MD5 89 3.9.3.3 SHA-1 89 3.9.3.4 RIPEMD-160 90 3.9.4 Compression Algorithms: zlib 90 3.10 Threats SSH Can Counter 90 3.10.1 Eavesdropping 90 3.10.2 Name Service and IP Spoofing 90 3.10.3 Connection Hijacking 91 3.10.4 Man-in-the-Middle Attacks 91 Figure 3.8. Man-in-the-middle attack 91 3.10.5 The Insertion Attack 92 3.11 Threats SSH Doesn't Prevent 92 3.11.1 Password Cracking 92 3.11.2 IP and TCP Attacks 93 3.11.3 Traffic Analysis 94 3.11.4 Covert Channels 94 3.11.5 Carelessness 95 3.12 Summary 95 Chapter 4. Installation and Compile-Time Configuration 96 4.1 SSH1 and SSH2 96 4.1.1 Features 96 4.1.2 Obtaining the Distribution 97 4.1.2.1 Extracting the files 97 4.1.2.2 Verifying with PGP 97 4.1.3 Building and Installing SSH1 98 4.1.4 Building and Installing SSH2 98 4.1.4.1 SSH1 and SSH2 on the same machine 99 4.1.5 Compile-Time Configuration 99 Figure 4.1. SSH compile-time configuration (highlighted parts) 100 4.1.5.1 Configuration standards 101 4.1.5.2 Installation, files, and directories 102 4.1.5.3 TCP/IP support 103 4.1.5.4 X window support 104 4.1.5.5 TCP port forwarding 105 4.1.5.6 Encryption and ciphers 105 4.1.5.7 Authentication 106 4.1.5.8 SOCKS proxy support 107 4.1.5.9 User logins and shells 108 4.1.5.10 Forbidding logins 109 4.1.5.11 scp behavior 109 4.1.5.12 R-commands (rsh) compatibility 110 4.1.5.13 SSH-1/SSH-2 agent compatibility 110 4.1.5.14 Debug output 111 4.1.6 Creating the Serverwide Known-Hosts File 111 4.1.6.1 make-ssh-known-hosts command-line flags 112 4.2 F-Secure SSH Server 114 4.2.1 Obtaining and Installing 114 4.3 OpenSSH 115 4.3.1 Prerequisites 115 4.3.2 Building 115 4.3.3 PAM 115 4.3.4 Randomness 116 4.3.5 Compilation Flags 116 4.4 Software Inventory 118 118 Table 4.1. Software Inventory 118 4.5 Replacing R-Commands with SSH 119 4.5.1 The /usr/hosts Directory 120 4.5.2 Concurrent Version System (CVS) 120 4.5.3 GNU Emacs 121 4.5.4 Pine 121 4.5.5 rsync, rdist 122 4.6 Summary 122 Chapter 5. Serverwide Configuration 123 5.1 The Name of the Server 123 5.2 Running the Server 124 5.2.1 Running as the Superuser 124 5.2.2 Running as an Ordinary User 125 5.3 Server Configuration: An Overview 126 126 Figure 5.1. Serverwide configuration (highlighted parts) 126 5.3.1 Server Configuration Files 127 5.3.2 Command-Line Options 128 5.3.3 Changing the Configuration 128 5.3.4 A Tricky Reconfiguration Example 130 5.4 Getting Ready: Initial Setup 130 5.4.1 File Locations 130 5.4.1.1 Host key files 131 5.4.1.2 Random seed file 131 5.4.1.3 Process ID file 132 5.4.1.4 Server configuration file 132 5.4.1.5 User SSH directory 132 5.4.1.6 Per-account authorization files 133 5.4.2 File Permissions 133 5.4.2.1 Acceptable permissions for user files 133 5.4.2.2 Permissions for newly created files 134 5.4.3 TCP/IP Settings 135 5.4.3.1 Port number and network interface 135 5.4.3.2 Invocation by inetd 136 5.4.3.3 Idle connections 136 5.4.3.4 KeepAlive 137 5.4.3.4.1 KeepAlive and connection timeouts 137 5.4.3.5 Failed logins 138 5.4.3.6 Limiting simultaneous connections 139 5.4.3.7 Reverse IP mappings 139 5.4.3.8 Controlling TCP_NODELAY 140 5.4.3.9 Discovering other servers 140 5.4.3.10 Agent forwarding 140 5.4.3.11 Forwarding 141 5.4.4 Server Key Generation 141 5.4.5 Encryption Algorithms 142 5.4.5.1 MAC algorithms 144 5.4.6 SSH Protocol Selection 144 5.5 Letting People in: Authentication and Access Control 144 5.5.1 Authentication 144 Table 5.1. Authentication-Related Keywords 146 5.5.1.1 Password authentication 146 5.5.1.2 Public-key authentication 146 5.5.1.3 Rhosts authentication 147 5.5.1.4 Stronger trusted-host authentication 148 5.5.1.5 Fetching public keys of known hosts 148 5.5.1.6 PGP authentication 149 5.5.1.7 Kerberos authentication 150 5.5.1.8 TIS authentication 152 5.5.1.9 SecurID authentication 152 5.5.1.10 S/Key authentication 152 5.5.1.11 PAM authentication 153 5.5.1.12 AFS token passing 153 5.5.2 Access Control 153 Figure 5.2. Access control levels 154 5.5.2.1 Account access control 154 5.5.2.2 Group access control 157 5.5.2.3 Hostname access control 158 5.5.2.4 shosts access control 159 5.5.2.5 Root access control 160 Table 5.2. Can root Log In? 160 5.5.2.6 Restricting directory access with chroot 160 5.5.2.7 Summary of authentication and access control 161 Table 5.3. SSH1 and OpenSSH Summary of Authentication and Access Control 161 Table 5.4. SSH2 Summary of Authentication and Access Control 162 5.5.3 Selecting a Login Program 162 5.6 User Logins and Accounts 163 5.6.1 Welcome Messages for the User 163 5.6.2 Expired Account or Password 163 5.6.3 Empty Passwords 164 5.6.4 Arbitrary Actions with /etc/sshrc 164 5.6.4.1 /etc/nologin 165 5.7 Subsystems 165 5.7.1 Disabling the Shell Startup File 166 5.8 History, Logging, and Debugging 166 5.8.1 Logging and SSH1 167 5.8.1.1 SSH1 Fascist Logging mode 167 5.8.1.2 SSH1 Debug mode 168 5.8.1.3 SSH1 Quiet mode 169 Table 5.5. Behavior of SSH1 Quiet Mode 170 5.8.2 Logging and SSH2 170 5.8.2.1 SSH2 Debug mode (general) 170 Example 5.1. SSH2 Debug Levels 171 5.8.2.2 SSH2 Debug mode (module-based) 171 Table 5.6. SSH2 Module Names 172 5.8.2.3 Debugging sshd2 -i 173 5.8.2.4 SSH2 verbose mode 174 5.8.2.5 SSH2 Fascist Logging mode 174 5.8.2.6 SSH2 quiet mode 174 5.8.3 Logging and OpenSSH 174 5.8.3.1 Absence of RSA support 175 5.9 Compatibility Between SSH-1 and SSH-2 Servers 175 5.9.1 Security Issues with SSH-1 Compatibility Mode in SSH2 176 5.10 Summary 176 Chapter 6. Key Management and Agents 177 177 177 Figure 6.1. SSH user key and agent configuration (highlighted parts) 177 6.1 What Is an Identity? 178 178 Figure 6.2. SSH identity files (private keys) and the programs that use them 178 Figure 6.3. SSH authorization files (public keys) and the programs that use them 179 6.1.1 SSH1 Identities 179 6.1.2 SSH2 Identities 179 6.1.3 OpenSSH Identities 180 6.2 Creating an Identity 180 6.2.1 Generating RSA Keys for SSH1 181 6.2.2 Generating RSA/DSA Keys for SSH2 183 6.2.3 Generating RSA/DSA Keys for OpenSSH 185 6.2.4 Selecting a Passphrase 186 6.3 SSH Agents 186 6.3.1 Agents Don't Expose Keys 188 Figure 6.4. How an SSH agent works with its clients 188 6.3.2 Starting an Agent 188 6.3.2.1 Single-shell method 189 6.3.2.2 Subshell method 191 Table 6.1. Pros and Cons of Invoking an Agent 191 6.3.2.3 Format of environment variable commands 192 6.3.2.4 SSH-1 and SSH-2 agent compatibility 192 6.3.3 Loading Keys with ssh-add 193 6.3.3.1 Automatic agent loading (single-shell method) 197 6.3.3.2 Automatic agent loading (subshell method) 198 6.3.3.3 Automatic agent loading (X Window System) 199 6.3.4 Agents and Security 199 6.3.4.1 Access control 199 6.3.4.2 Cracking an agent 200 6.3.5 Agent Forwarding 200 6.3.5.1 A firewall example 201 Figure 6.5. Bastion host scenario 201 Figure 6.6. Solution with SSH agent forwarding 201 6.3.5.2 How agent forwarding works 202 Figure 6.7. How agent forwarding works 202 6.3.5.3 Enabling agent forwarding 203 6.3.6 Agent CPU Usage 204 6.4 Multiple Identities 204 6.4.1 Switching Identities Manually 205 Table 6.2. Syntax Summary 205 6.4.2 Switching Identities with an Agent 205 6.4.3 Tailoring Sessions Based on Identity 206 6.5 Summary 206 Chapter 7. Advanced Client Use 208 208 208 Figure 7.1. Client configuration (highlighted parts) 208 7.1 How to Configure Clients 208 7.1.1 Environment Variables 209 7.1.2 Command-Line Options 209 7.1.3 Client Configuration Files 209 7.1.3.1 Keywords versus command-line options 210 7.1.3.2 Global and local files 211 7.1.3.3 Configuration file sections 211 7.1.3.4 Multiple matches 213 Figure 7.2. SSH1 client configuration file with multiple matches (SSH2 not shown) 213 7.1.3.5 Making nicknames for hosts 214 7.1.3.6 Comments, indenting, and style 216 7.2 Precedence 217 7.3 Introduction to Verbose Mode 217 7.4 Client Configuration in Depth 218 7.4.1 Remote Account Name 218 7.4.1.1 Tricks with remote account names 219 7.4.2 User Identity 221 7.4.3 Host Keys and Known-Hosts Databases 222 7.4.3.1 Strict host key checking 222 Table 7.1. StrictHostKeyChecking Behavior 223 7.4.3.2 Moving the known hosts files 224 7.4.4 TCP/IP Settings 224 7.4.4.1 Selecting a remote port 224 7.4.4.2 Forcing a nonprivileged local port 225 7.4.4.3 Keepalive messages 226 7.4.4.4 Controlling TCP_NODELAY 227 7.4.4.5 Requiring IPv4 and IPv6 227 7.4.5 Making Connections 227 7.4.5.1 Number of connection attempts 227 7.4.5.2 Password prompting in SSH1 228 7.4.5.3 Password prompting in SSH2 229 7.4.5.4 Batch mode: suppressing prompts 229 7.4.5.5 Pseudo-terminal allocation (TTY/PTY/PTTY) 229 7.4.5.6 Backgrounding a remote command 231 7.4.5.7 Backgrounding a remote command, take two 231 7.4.5.8 RSH issues 232 7.4.5.9 Escaping 233 7.4.6 Proxies and SOCKS 234 Figure 7.3. A typical SOCKS installation 234 7.4.6.1 SOCKS in SSH1 236 7.4.6.2 SOCKS in SSH2 236 7.4.6.3 SOCKS in OpenSSH 237 7.4.6.4 Other SOCKS issues 238 7.4.7 Forwarding 238 7.4.8 Encryption Algorithms 238 7.4.8.1 MAC algorithms 239 7.4.9 Session Rekeying 239 7.4.10 Authentication 239 7.4.10.1 Requesting an authentication technique 239 7.4.10.2 The server is the boss 240 7.4.10.3 Detecting successful authentication 240 7.4.11 Data Compression 242 Table 7.2. Effect of Compression and CompressionLevel 243 7.4.12 Program Locations 243 7.4.13 Subsystems 243 7.4.14 SSH1/SSH2 Compatibility 243 7.4.15 Logging and Debugging 244 7.4.16 Random Seeds 245 7.5 Secure Copy with scp 245 7.5.1 Full Syntax 246 Table 7.3. scp Path Specifications 248 7.5.2 Handling of Wildcards 248 7.5.3 Recursive Copy of Directories 248 7.5.4 Preserving Permissions 249 7.5.5 Automatic Removal of Original File 249 7.5.6 Safety Features 249 7.5.7 Statistics Display 250 7.5.7.1 scp1 statistics 250 Table 7.4. Controlling Statistics in scp1 251 7.5.7.2 scp2 statistics 251 7.5.8 Locating the ssh Executable 252 7.5.9 For Internal Use Only 252 7.6 Summary 253 Chapter 8. Per-Account Server Configuration 254 254 254 Figure 8.1. Per-account configuration (highlighted parts) 254 8.1 Limits of This Technique 254 8.1.1 Overriding Serverwide Settings 255 8.1.2 Authentication Issues 255 8.2 Public Key-Based Configuration 255 8.2.1 SSH1 Authorization Files 256 8.2.2 SSH2 Authorization Files 257 8.2.2.1 SSH2 PGP key authentication 258 8.2.3 OpenSSH Authorization Files 258 8.2.4 Forced Commands 258 Figure 8.2. Forced command substituting /bin/who for /bin/ls 258 8.2.4.1 Security issues 259 8.2.4.2 Rejecting connections with a custom message 260 8.2.4.3 Displaying a command menu 261 Example 8.1. Menu Script 261 8.2.4.4 Examining the client's original command 262 8.2.4.5 Restricting a client's original command 263 8.2.4.6 Logging a client's original command 264 8.2.4.7 Forced commands and secure copy (scp) 264 8.2.5 Restricting Access by Host or Domain 264 8.2.5.1 Simulating "from" with SSH2 265 8.2.6 Setting Environment Variables 266 8.2.6.1 Example: CVS and $LOGNAME 267 8.2.7 Setting Idle Timeout 268 8.2.8 Disabling Forwarding 269 8.2.9 Disabling TTY Allocation 269 8.3 Trusted-Host Access Control 271 8.4 The User rc File 272 8.5 Summary 272 Chapter 9. Port Forwarding and X Forwarding 273 9.1 What Is Forwarding? 274 274 Figure 9.1. SSH forwarding 274 9.2 Port Forwarding 274 9.2.1 Local Forwarding 275 9.2.1.1 Local forwarding and GatewayPorts 278 9.2.1.2 Remote forwarding 278 9.2.2 Trouble with Multiple Connections 279 9.2.3 Comparing Local and Remote PortForwarding 280 9.2.3.1 Common elements 280 Figure 9.2. Application client and server 280 Figure 9.3. Direct client/server connection (no forwarding) 281 Figure 9.4. A forwarded port 281 Figure 9.5. A forwarded connection 282 9.2.3.2 Local versus remote forwarding: the distinction 282 Figure 9.6. Local port forwarding 282 Figure 9.7. Remote port forwarding 283 9.2.4 Forwarding Off-Host 283 Figure 9.8. Off-host port forwarding 283 9.2.4.1 Privacy 284 9.2.4.2 Access control and the loopback address 284 9.2.4.3 Listening on ("binding") an interface 285 9.2.5 Bypassing a Firewall 285 Figure 9.9. Port forwarding through a firewall 285 9.2.6 Port Forwarding Without a Remote Login 286 9.2.6.1 One shot forwarding 287 9.2.7 The Listening Port Number 288 9.2.8 Choosing the Target Forwarding Address 289 9.2.9 Termination 289 9.2.9.1 The TIME_WAIT problem 290 9.2.10 Configuring Port Forwarding in the Server 290 9.2.10.1 Compile-time configuration 291 9.2.10.2 Serverwide configuration 291 9.2.10.3 Per-account configuration 292 9.3 X Forwarding 292 9.3.1 The X Window System 292 9.3.2 How X Forwarding Works 294 Figure 9.10. X forwarding 294 294 9.3.3 Enabling X Forwarding 295 9.3.4 Configuring X Forwarding 295 9.3.4.1 Compile-time configuration 295 9.3.4.2 Serverwide configuration 296 9.3.4.3 Per-account configuration 296 9.3.5 X Authentication 296 9.3.5.1 How X authentication works 297 9.3.5.2 xauth and the SSH rc files 297 9.3.5.3 Problems with X authentication 297 9.3.5.4 SSH and authentication spoofing 298 Figure 9.11. Authentication of forwarded X connections 298 9.3.5.5 Improving authentication spoofing 300 9.3.5.6 Nonstandard X clients 300 9.3.6 Further Issues 301 9.3.6.1 X server configuration 301 9.3.6.2 Setting your DISPLAY environment variable 301 9.3.6.3 Shared accounts 301 9.3.6.4 Location of the xauth program 302 9.3.6.5 X forwarding and the GatewayPorts feature 302 9.4 Forwarding Security: TCP-wrappers and libwrap 302 303 Figure 9.12. TCP-wrappers and SSH configuration (highlighted parts) 303 Figure 9.13. TCP-wrapper (libwrap) operation 304 9.4.1 TCP-wrappers Configuration 304 Example 9.1. Sample /etc/hosts.allow File 305 9.4.2 Notes About TCP-wrappers 306 9.5 Summary 307 Chapter 10. A Recommended Setup 308 10.1 The Basics 308 10.2 Compile-Time Configuration 308 10.3 Serverwide Configuration 309 10.3.1 Disable Other Means of Access 309 10.3.2 /etc/sshd_config 310 10.3.3 /etc/ssh2/sshd2_config 312 10.4 Per-Account Configuration 313 10.5 Key Management 313 10.6 Client Configuration 314 10.7 Remote Home Directories (NFS, AFS) 314 10.7.1 NFS Security Risks 315 10.7.2 NFS Access Problems 315 10.7.3 AFS Access Problems 316 10.8 Summary 316 Chapter 11. Case Studies 317 11.1 Unattended SSH: Batch or cron Jobs 317 11.1.1 Password Authentication 317 11.1.2 Public-Key Authentication 317 11.1.2.1 Storing the passphrase in the filesystem 317 11.1.2.2 Using a plaintext key 318 11.1.2.3 Using an agent 318 11.1.3 Trusted-Host Authentication 320 11.1.4 Kerberos 320 11.1.5 General Precautions for Batch Jobs 320 11.1.5.1 Least-privilege accounts 320 11.1.5.2 Separate, locked-down automation accounts 320 11.1.5.3 Restricted-use keys 321 11.1.5.4 Useful ssh options 321 11.1.6 Recommendations 321 11.2 FTP Forwarding 322 11.2.1 The FTP Protocol 322 Figure 11.1. Basic FTP operation: control connection and active- versus passive-mode transfers 324 11.2.2 Forwarding the Control Connection 324 Figure 11.2. Forwarding the control connection 324 11.2.2.1 Choosing the forwarding target 325 11.2.2.2 Using passive mode 326 11.2.2.3 The "PASV port theft" problem 327 Figure 11.3. "PASV port theft" 328 11.2.3 FTP, Firewalls, and Passive Mode 328 Figure 11.4. FTP client behind a firewall 329 11.2.4 FTP and Network Address Translation (NAT) 330 Figure 11.5. Client-side NAT prevents active-mode FTP transfers 330 11.2.4.1 Server-side NAT issues 330 Figure 11.6. Server-side NAT prevents passive-mode FTP transfers 331 11.2.5 All About Data Connections 332 11.2.5.1 The usual method of file transfer 332 11.2.5.2 Passive mode in depth 333 11.2.5.3 FTP with the default data ports 334 11.2.6 Forwarding the Data Connection 336 Figure 11.7. Forwarding the FTP data connection 337 11.3 Pine, IMAP, and SSH 339 11.3.1 Securing IMAP Authentication 339 Figure 11.8. A normal IMAP connection 339 Figure 11.9. Forwarding an IMAP connection 340 11.3.1.1 Pine and preauthenticated IMAP 340 Figure 11.10. Pine/IMAP over SSH, preauthenticated 340 11.3.1.2 Making Pine use SSH instead of rsh 341 11.3.2 Mail Relaying and News Access 343 11.3.3 Using a Connection Script 344 11.4 Kerberos and SSH 345 345 Figure 11.11. Kerberos configuration (highlighted parts) 345 11.4.1 Comparing SSH and Kerberos 346 11.4.1.1 Infrastructure 346 11.4.1.2 Integrating with other applications 347 11.4.1.3 Security of authenticators 347 11.4.1.4 Account administration 348 11.4.1.5 Performance 348 11.4.2 Using Kerberos with SSH 348 11.4.3 A Brief Introduction to Kerberos-5 349 11.4.3.1 Principals and tickets 349 11.4.3.2 Obtaining credentials with kinit 350 11.4.3.3 Listing credentials with klist 350 11.4.3.4 Running a kerberized application 350 11.4.3.5 Authorization 351 11.4.4 Kerberos-5 in SSH1 352 Figure 11.12. SSH with Kerberos authentication 353 11.4.4.1 Kerberos password authentication 353 11.4.4.2 Kerberos and NAT 353 Figure 11.13. Kerberos and NAT 354 11.4.4.3 Cross-realm authentication 354 11.4.4.4 TGT forwarding 357 11.4.4.5 SSH1 Kerberos ticket-cache bug 358 11.4.4.6 Kerberos-5 setup notes 358 11.4.5 Kerberos-4 in OpenSSH 360 Table 11.1. Differences Between Kerberos-4 and Kerberos-5 with Respect to SSH 360 11.4.5.1 Kerberos-4 compatibility mode in Kerberos-5 360 11.4.5.2 Kerberos on Solaris 361 11.5 Connecting Through a GatewayHost 361 11.5.1 Making Transparent SSH Connections 362 Figure 11.14. Proxy gateway 362 Figure 11.15. Chained SSH connections through a proxy gateway 362 11.5.2 Using SCP Through a Gateway 363 11.5.2.1 Passing along the remote command 364 11.5.2.2 Authentication 364 11.5.3 Another Approach: SSH-in-SSH(Port Forwarding) 365 Figure 11.16. Forwarded SSH connection through a proxy gateway 365 11.5.4 Security Differences 366 11.5.4.1 "Server-in-the-middle" attack 366 11.5.4.2 Server authentication 367 Chapter 12. Troubleshooting and FAQ 368 12.1 Debug Messages: Your First Line of Defense 368 12.1.1 Client Debugging 368 12.1.2 Server Debugging 368 12.2 Problems and Solutions 369 12.2.1 General Problems 369 12.2.2 Authentication Problems 371 12.2.2.1 General authentication problems 371 12.2.2.2 Password authentication 372 12.2.2.3 Trusted-host authentication 373 12.2.2.4 Public-key authentication 374 12.2.2.5 PGP key authentication 375 12.2.3 Key and Agent Problems 376 12.2.3.1 General key/agent problems 376 12.2.3.2 ssh-keygen 376 12.2.3.3 ssh-agent and ssh-add 377 12.2.3.4 Per-account authorization files 378 12.2.4 Server Problems 378 12.2.4.1 sshd_config, sshd2_config 378 12.2.5 Client Problems 379 12.2.5.1 General client problems 379 12.2.5.2 Client configuration file 379 12.2.5.3 ssh 380 12.2.5.4 scp 381 12.2.5.5 sftp2 383 12.2.5.6 Port forwarding 384 12.3 Other SSH Resources 385 12.3.1 Web Sites 386 12.3.2 Usenet Newsgroups 386 12.3.3 Mailing Lists 386 12.4 Reporting Bugs 387 Chapter 13. Overview of Other Implementations 388 13.1 Common Features 388 13.2 Covered Products 388 13.3 Table of Products 389 13.4 Other SSH-Related Products 395 Chapter 14. SSH1 Port by Sergey Okhapkin (Windows) 396 14.1 Obtaining and Installing Clients 396 14.1.1 Prepare Folders 396 14.1.2 Prepare autoexec.bat 397 14.1.3 Create a Password File 397 14.1.4 Install Cygwin 397 14.1.5 Install bzip2 398 14.1.6 Install Okhapkin's SSH1 398 14.1.7 Create a Key Pair 398 14.1.8 Log into a Remote Host with ssh1 399 14.1.9 Copy Files Securely with scp1 399 14.2 Client Use 400 14.3 Obtaining and Installing the Server 400 14.3.1 Obtain sshd 400 14.3.2 Obtain the NT Resource Kit 400 14.3.3 Create an Administrative User 400 14.3.4 Install the Server 401 14.3.5 Generate Host Key 401 14.3.6 Edit sshd_config 401 14.3.7 Run the Server 401 14.3.8 Test the Server 402 14.3.9 Terminate the Server 402 14.4 Troubleshooting 402 14.5 Summary 403 Chapter 15. SecureCRT (Windows) 404 15.1 Obtaining and Installing 404 15.2 Basic Client Use 404 404 Figure 15.1. Secure CRT Session Options window 404 15.3 Key Management 405 15.3.1 RSA Key Generation Wizard 405 15.3.2 Using Multiple Identities 406 15.4 Advanced Client Use 406 15.4.1 Mandatory Fields 406 15.4.2 Data Compression 407 15.4.3 TIS Authentication 407 15.4.4 Firewall Use 407 15.5 Forwarding 407 15.5.1 Port Forwarding 407 Figure 15.2. SecureCRT Port Forwarding tab 408 15.5.2 X Forwarding 408 15.6 Troubleshooting 409 15.6.1 Authentication 409 15.6.2 Forwarding 409 15.7 Summary 410 Chapter 16. F-Secure SSH Client (Windows, Macintosh) 411 16.1 Obtaining and Installing 411 16.2 Basic Client Use 411 411 Figure 16.1. F-Secure SSH Client Connection properties window 411 16.3 Key Management 412 16.3.1 Generating Keys 412 16.3.2 Importing Existing Keys 412 16.3.3 Installing Public Keys 413 16.3.4 Using Keys 413 16.4 Advanced Client Use 413 16.4.1 Data Compression 414 16.4.2 Debugging with Verbose Mode 414 16.4.3 SOCKS Proxy Server 414 16.4.4 Accepting Host Keys 414 16.4.5 Additional Security Features 414 16.4.6 Secure File Transfer with SFTP 415 16.4.7 Command-Line Tools 415 16.5 Forwarding 415 16.5.1 Port Forwarding 415 Figure 16.2. F-Secure SSH Client local port forwarding options 416 16.5.2 X Forwarding 416 16.6 Troubleshooting 417 16.7 Summary 418 Chapter 17. NiftyTelnet SSH (Macintosh) 419 17.1 Obtaining and Installing 419 419 Figure 17.1. NiftyTelnet New Connection dialog box 419 17.2 Basic Client Use 420 420 Figure 17.2. NiftyTelnet SSH Settings window 420 17.2.1 Authentication 420 17.2.2 Scp 420 Figure 17.3. NiftyTelnet Scp window 421 17.2.3 Host Keys 421 17.3 Troubleshooting 421 17.4 Summary 422 Appendix A. SSH2 Manpage for sshregex 423 423 Description 423 Patterns 423 Character Sets 424 Example 425 Authors 425 See also 425 Appendix B. SSH Quick Reference 426 2.1 Legend 426 2.2 sshd Options 426 2.3 sshd Keywords 427 2.4 ssh and scp Keywords 431 2.5 ssh Options 433 2.6 scp Options 434 2.7 ssh-keygen Options 435 2.8 ssh-agent Options 436 2.9 ssh-add Options 436 2.10 Identity and Authorization Files 436 2.11 Environment Variables 437 Colophon 438 Secure your computer network with SSH! With end-to-end strong encryption, reliable public-key authentication, and a highly configurable client/server architecture, SSH (Secure Shell) is a popular, robust, TCP/IP-based solution to many network security and privacy concerns. It supports secure remote logins, secure file transfer between computers, and a unique "tunneling" capability that adds encryption to otherwise insecure network applications. Best of all, SSH is free, with feature-filled commercial versions available as well. SSH, The Secure Shell: The Definitive Guide covers the Secure Shell in detail for both system administrators and end users. It demystifies the SSH man pages and includes thorough coverage of: * Basic to advanced use of SSH client tools for Unix, Windows, and Macintosh. * Installing, configuring, and maintaining SSH (with special tips for large data centers). * The three levels of SSH server control: compile-time and server-wide configuration for administators, and per-account configuration for end users. * Application tunneling, port and agent forwarding, and forced commands. * Undocumented features of popular SSH implementations. * Detailed case studies of creating complex applications with SSH. * Troubleshooting a wide variety of common and not-so-common problems.Whether you're communicating on a small LAN or across the Internet, SSH can ship your data from "here" to "there" efficiently and securely. So throw away those insecure .rhosts and hosts.equiv files, move up to SSH, and make your network a safe place to live and work. Secure your computer network with SSH! With transparent, strong encryption, reliable public-key authentication, and a highly configurable client/server architecture, SSH (Secure Shell) is a popular, robust, TCP/IP-based solution to many network security and privacy concerns. It supports secure remote logins, secure file transfer between computers, and a unique ''tunneling'' capability that adds encryption to otherwise insecure network applications. Best of all, SSH is free, with feature-filled commercial versions available as well. __SSH: The Secure Shell: The Definitive Guide__ covers the Secure Shell in detail for both system administrators and end users. It demystifies the SSH man pages and includes thorough coverage of: * SSH1, SSH2, OpenSSH, and F-Secure SSH for Unix, plus Windows and Macintosh products: the basics, the internals, and complex applications. * Configuring SSH servers and clients, both system-wide and per user, with recommended settings to maximize security. * Advanced key management using agents, agent forwarding, and forced commands. * Forwarding (tunneling) of TCP and X11 applications in depth, even in the presence of firewalls and network address translation (NAT). * Undocumented behaviors of popular SSH implementations. * Installing and maintaining SSH systems. Whether you're communicating on a small LAN or across the Internet, SSH can ship your data from ''here'' to ''there'' efficiently and securely. So throw away those insecure .rhosts and hosts.equiv files, move up to SSH, and make your network a safe place to live and work.