1 TITLE: Open Secure SHell (OpenSSH)
3 AUTHOR: Daniel Roethlisberger <daniel@roe.ch>
6 How to compile and install the OpenSSH daemon and client.
9 HINT VERSION: 1.5 (17-May-2002)
10 CHANGES: 1.5: Latest instructions on privilege separated openssh.
11 1.4: Latest versions, added more openssh options, and a
12 number of other, minor changes.
13 1.3: Updated zlib web site.
14 1.2: Upgraded to latest openssh/openssl. Removed obsolete
15 workaround for broken openssl installation, added man
16 page fix. Enabled MD5 in openssh.
17 1.1: Incorporated comments by Sergey Ostrovsky regarding
18 OpenSSL configuration, optimization and the broken
19 install script. OpenSSL install is much improved now.
20 Added comments on install location. Modified the
21 random devices script a bit.
27 This document describes the necessary steps to get a fully functional
28 SSH daemon (sshd), and the SSH clients (ssh, scp). OpenSSH contains
29 replacements for the aged, insecure and unencrypted telnet, rlogin, rcp and
30 ftp services. With SSH, SFTP and SCP, you have a secure, encrypted
31 alternative. In addition, you can tunnel about anything you can think of
32 through secure, encrypted SSH tunnels.
34 Why "Open"? There is a commercial package from Tatu Ylönen which is
35 here for essentially the same thing. The commercial variant has several
36 drawbacks, for instance the license doesn't permit using it freely in
37 commercial environments, while OpenSSH has an open license, is free from any
38 patent issues, and no cryptographic part of it was ever exported from the US,
39 which means no ITAR export regulation problems. So in essence, OpenSSH is
40 completely free, while the commercial SSH is not. In addition, one might say
41 that Tatu has been a little unfriendly to the free SSH offspring in the past,
42 so for me the commercial variant is out of the question.
48 You'll need at least the following three packages to get
51 openssh-3.2.2p1.tar.gz from http://www.openssh.com/portable.html
52 openssl-0.9.6c.tar.gz from http://www.openssl.org/
53 zlib.tar.gz from http://www.gzip.org/zlib/
55 You may also get them from a mirror, such as your local sunsite. You
56 are advised to get the latest stable release available. There have been
57 several serious flaws in both openssl and even more so openssh lately, so
58 make sure you are up to date, always. Consider subscribing to the announce
59 mailing lists of openssh and openssl, so you'll know when new releases are
60 available. Upgrading these two frequently is crucual to your system security.
62 zlib is a compression library required to build the OpenSSL and
63 OpenSSH packages. OpenSSL is an open SSL implementation library. OpenSSH is
64 using OpenSSL for all its crypto-related tasks.
70 If you want to use SSH in conjunction with PAM, install PAM first.
71 See the PAM-hint on how to do this. PAM is in no way required to run any part
72 of OpenSSH, but if you want a PAM aware version of OpenSSH, you need to have
73 PAM installed first. You are entirely on your own when building for PAM.
79 If you haven't already done so, you should create the /dev/random and
80 /dev/urandom random character generator device files. OpenSSH comes with an
81 internal random data generator, but it is strongly recommended to use the
82 random device provided by the Linux kernel. You do so by typing the following
85 mknod /dev/random c 1 8 &&
86 mknod /dev/urandom c 1 9 &&
87 chown root.sys /dev/random /dev/urandom &&
88 chmod 0644 /dev/random /dev/urandom
90 The kernel random data generator takes some of its random input
91 ("noise"), from user interaction such as mouse, keyboard, network delays,
92 and so forth. When a Linux system starts up without much outside world
93 interaction, the entropy pool may be in a fairly predictable state. This
94 reduces the actual amount of noise in the entropy pool below the estimate.
95 In order to counteract this effect, it helps to carry entropy pool
96 information across shut-downs and start-ups.
98 To do this, add the following lines to an appropriate script which is
99 run during the Linux system start-up sequence:
101 echo -n "Initializing kernel random number generator..."
102 # Initialize kernel random number generator with random seed
103 # from last shut-down (or start-up) to this start-up. Load and
104 # then save 512 bytes, which is the size of the entropy pool.
105 if [ -f /var/random-seed ]; then
106 cat /var/random-seed >/dev/urandom
108 dd if=/dev/urandom of=/var/random-seed count=1 &>/dev/null
111 Also, add the following lines in an appropriate script which is run
112 during the Linux system shutdown:
114 # Carry a random seed from shut-down to start-up for the random
115 # number generator. Save 512 bytes, which is the size of the
116 # random number generator's entropy pool.
117 echo -n "Saving random seed..."
118 dd if=/dev/urandom of=/var/random-seed count=1 &>/dev/null
125 A note on installation paths: I installed all the three packages into
126 the /usr hierarchy. If you want to keep LFS base and additional packages
127 you've installed later strictly separated, you'll want to replace /usr with
128 /usr/local wherever I've used it in the following commands.
134 After you've made sure you got working random devices, install zlib
135 first. Do this by unpacking the tarball as usual, and running the following
136 commands from within the zlib source directory.
138 ./configure --shared --prefix=/usr &&
147 Then, install OpenSSL as shared libraries the same way, but running
150 ./config --prefix=/usr --openssldir=/usr/lib/openssl shared &&
154 for m in /usr/lib/openssl/man/man? ; do
155 cp $m/* /usr/man/$(basename $m)/
159 You might have noticed that OpenSSL does not read the CFLAGS compiler
160 flags variable from the environment, but instead defaults to -O3 -m486. You
161 might want to edit ./Configure, find the line beginning with "linux-elf"
162 (including quotes) and set the processor model and optimization desired. I've
163 used -O3 -march=i686 -mcpu=i686 . You may also want to play with other flags.
165 If you don't want any patented algorithms, you can supply the options
166 no-rc5 and no-idea to ./configure. That will skip support for those two
167 patented algorithms. I want RC5 and IDEA no matter the patent issues.
169 By default, the OpenSSL configuration script copies its configuration
170 tree into $(prefix)/ssl. That violates the File Hierarchy Standard, and
171 besides clutters the directory tree, thus we override this with the
172 --openssldir switch, and have the script install the libraries where they
173 belong to: into $(prefix)/lib/openssl.
179 First, we need to do some preparations for the nifty privilege
180 separation feature introduced in openssh-3.2.2 . The privilege separated
181 SSH daemon is significantly more secure, as all the untrusted data
182 processing is done in unprivileged processes, which means that bugs that
183 would normally lead to a remote root compromise are now only leading to
184 unprivileged user access within an empty chroot jail. Or in plain old
185 English: remote root exploits that would normally work against OpenSSH do
186 not work against the privilege separated version. Or at least chances are
187 extremely slim that a hole leads to remote root.
189 Create user and group 'sshd' by editing /etc/passwd, /etc/shadow,
190 and /etc/group. Make the user sshd member of the group sshd, and no other
191 groups. Set the home directory of the user to be /var/empty, and the shell
192 to /bin/false. Then create that special directory by running:
195 chown root:root /var/empty &&
198 Take special care that there is not a single file in the whole
199 filesystem that has user or group sshd. /var/empty must have owner and
200 group root, not sshd.
202 Now, install OpenSSH itself by running the following commands within
203 its directory created by tar:
205 ./configure --prefix=/usr --sysconfdir=/etc/ssh \
206 --with-md5-passwords \
208 --with-ipv4-default &&
212 This installs the binaries into /usr/bin and sbin, and the
213 configuration files, including all host keys, into /etc/ssh. make install
214 will create the /etc/ssh directory if not already present. New host keys will
215 automatically be generated. Those keys are 1024 bits by default. If you want
216 to create new or larger host keys manually later, use ssh-keygen to do so. If
217 you use SSH protocol versions 1, you might want to raise the ServerKeyBits
218 setting from the default 768 to 1024.
220 You may need more ./configure options if you want to enable support
221 for the likes of Kerberos, smartcards, PAM or AFS, or if you want to change
222 the privilege separation defaults (/var/empty, sshd). Note that I install
223 the ssh binary -not- suid root. Root privileges are needed by the client
224 only when using rhosts for authentication, which requires ssh to bind to a
225 privileged port. Since rhosts is an old, deprecated authentication method,
226 insecure by design, I'm not using it, and neither should you.
232 To enable privilege separation, edit /etc/ssh/sshd_config and add
235 UsePrivilegeSeparation yes
237 For improved security, you might want to tune other paramters,
238 such as disable SSH protocol v1 support, and you might want to disable
239 rhosts authentification. I usually only allow password and pubkey
240 authentication on my hosts (man sshd).
246 If you want the SSH daemon (sshd) to be started by init on bootup,
247 create a copy of /etc/init.d/template, name it sshd, edit it, put as binary
248 path /usr/sbin/sshd where appropriate, make sure the scripts output is to
249 your liking, and then create symlinks in the appropriate runlevel directories.
250 On my box, I added "S20sshd" symlink in rc{3,4,5}.d, and "K40sshd" in
251 rc{0,1,2,6}.d, all pointing to "../init.d/sshd". Note that your LFS may be
252 using three digits, in which case make sure you create S200sshd and K400sshd
255 To immediately start sshd, and to make sure the script works as it
256 should, start the daemon via the script by running:
258 /etc/init.d/sshd start
260 In case you have telnetd or any of the BSD r-daemons running, you will
261 want disable them, and tell your users to use ssh, scp and sftp instead. SFTP
262 is now reasonably widespread, there are clients for just about every OS out
263 there, including Windows, so you really ought to have your users use SFTP, and
264 disable FTP access to system users.
266 If you want to run sshd chrooted, you can write a simple program which
267 does the chroot to the user homedir, drops privileges, cleans the env, and
268 runs a shell. Install this chroot program suid root, add it to /etc/shells,
269 and use it as the users shell. Don't forget to set up the chroot environment
270 for the users in question (eg., sftp requires not only a bin/sh but also the
271 sftp-server binary). You should also make sure that the user in question does
272 not own anything in the chroot jail, and you might want to set the immutable
273 bit on all the jail files if you are using a filesystem which supports it
274 (man chattr). An alternative to using a suid root chroot wrapper is to patch
275 the sshd and sftp-server binaries. Finding and applying those patches is up to
276 you, I assure you they exist, however I prefer the wrapper. You are on your
279 By the way, if you're looking for a free win SSH client, check out
280 PuTTY, which you'll find at the following URL. There's a lot of other clients
281 as well, so take your pick.
283 http://www.freessh.org/
285 People really shouldn't have to use any unencrypted protocols for
286 authentication anymore. There's just no reason left to do so.