<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.saruman.biz/saruwiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Saruman%21</id>
	<title>SaruWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.saruman.biz/saruwiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Saruman%21"/>
	<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php/Special:Contributions/Saruman!"/>
	<updated>2026-05-02T07:19:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3110</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3110"/>
		<updated>2021-09-23T15:06:31Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users.&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian Jessie base server|Debian 8 Jessie base server]] is a howto on the installation of a very basic Linux box under Jessie (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; and &#039;&#039;btrfs&#039;&#039; for [[software-based RAID]] contains our ideas and observations on data redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication and security&#039;&#039;&#039;&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your own LAMP server&#039;&#039;&#039;&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Other server apps&#039;&#039;&#039;&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
* How to create [[your own ownCloud]] server (and here&#039;s [http://www.thecomputerkid.com/2013/06/why-you-should-use-owncloud.html why] you should do this)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3095</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3095"/>
		<updated>2016-10-29T20:25:09Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* We&amp;#039;ve got the CA certificate, now what? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/ssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/ssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/ssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key - note that you&#039;ll have to provide the passphrase to complete this command:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers (and again, you&#039;ll have to provide the passphrase to read the private key). Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got the following things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file;&lt;br /&gt;
* sign certificates for our own use;&lt;br /&gt;
* distribute the public CA certificate to every machine/person that may need to verify certificates that we&#039;ve signed.&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. At the very least, you have to make sure the private key is owned by root or an administrative account, and is &#039;&#039;not&#039;&#039; world-readable. It might even be wise to remove the private key altogether, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;br /&gt;
&lt;br /&gt;
The last point means we need to send out our public CA certificate. In some cases, you can provide others with your &#039;&#039;.pem&#039;&#039; file, but in other cases you&#039;re better off providing a simpler &#039;&#039;.crt&#039;&#039; file. The difference is explained nicely at the [http://info.ssl.com/article.aspx?id=12149 ssl.com site]&lt;br /&gt;
To create a public CA certificate in .crt format you can issue the following command:&lt;br /&gt;
 openssl x509 -outform der -in cacert.pem -out cacert.crt&lt;br /&gt;
By the way, it&#039;s usually better to distribute the public certificate with a more recognizable file name, such as &#039;&#039;saruman.bizRootCA.crt&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3094</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3094"/>
		<updated>2016-10-29T20:23:57Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Creating the CA root certificate key pair */  added passphrase&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/ssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/ssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/ssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key - note that you&#039;ll have to provide the passphrase to complete this command:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers (and again, you&#039;ll have to provide the passphrase to read the private key). Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got the following things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file;&lt;br /&gt;
* sign certificates for our own use;&lt;br /&gt;
* distribute the public CA certificate to every machine/person that may need to verify certificates that we&#039;ve signed.&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. At the very least, you have to make sure the private key is owned by root or an administrative account, and is &#039;&#039;not&#039;&#039; world-readable. It might even be wise to remove the private key altogether, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;br /&gt;
&lt;br /&gt;
The last point means we need to send out our public CA certificate. In some cases, you can provide others with your &#039;&#039;.pem&#039;&#039; file, but in other cases you&#039;re better off providing a simpler &#039;&#039;.crt&#039;&#039; file. The difference is explained nicely at the [http://info.ssl.com/article.aspx?id=12149 ssl.com site]&lt;br /&gt;
To create a public CA certificate in .crt format you can issue the following command:&lt;br /&gt;
 openssl x509 -outform der -in cacert.pem -out cacert.crt&lt;br /&gt;
By the way, it&#039;s usually better to distribute the public certificate with a more recognizable file name, such as &#039;&#039;saruman.biz.crt&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3093</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3093"/>
		<updated>2016-10-29T20:21:48Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* We&amp;#039;ve got the CA certificate, now what? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/ssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/ssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/ssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers. Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got the following things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file;&lt;br /&gt;
* sign certificates for our own use;&lt;br /&gt;
* distribute the public CA certificate to every machine/person that may need to verify certificates that we&#039;ve signed.&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. At the very least, you have to make sure the private key is owned by root or an administrative account, and is &#039;&#039;not&#039;&#039; world-readable. It might even be wise to remove the private key altogether, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;br /&gt;
&lt;br /&gt;
The last point means we need to send out our public CA certificate. In some cases, you can provide others with your &#039;&#039;.pem&#039;&#039; file, but in other cases you&#039;re better off providing a simpler &#039;&#039;.crt&#039;&#039; file. The difference is explained nicely at the [http://info.ssl.com/article.aspx?id=12149 ssl.com site]&lt;br /&gt;
To create a public CA certificate in .crt format you can issue the following command:&lt;br /&gt;
 openssl x509 -outform der -in cacert.pem -out cacert.crt&lt;br /&gt;
By the way, it&#039;s usually better to distribute the public certificate with a more recognizable file name, such as &#039;&#039;saruman.biz.crt&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3092</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3092"/>
		<updated>2016-10-29T20:12:05Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: corrected directory name - /etc/ssl not /etc/openssl&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/ssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/ssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/ssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/ssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers. Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got the following things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file;&lt;br /&gt;
* sign certificates for our own use;&lt;br /&gt;
* distribute the public CA certificate to every machine/person that may need to verify certificates that we&#039;ve signed.&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;br /&gt;
The last point means we need to send out our public CA certificate. In some cases, you can provide others with your &#039;&#039;.pem&#039;&#039; file, but in other cases you&#039;re better off providing a simpler &#039;&#039;.crt&#039;&#039; file. The difference is explained nicely at the [http://info.ssl.com/article.aspx?id=12149 ssl.com site]&lt;br /&gt;
To create a public CA certificate in .crt format you can issue the following command:&lt;br /&gt;
 openssl x509 -outform der -in cacert.pem -out cacert.crt&lt;br /&gt;
By the way, it&#039;s usually better to distribute the public certificate with a more recognizable file name, such as &#039;&#039;saruman.biz.crt&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3091</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3091"/>
		<updated>2016-10-29T20:06:52Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* We&amp;#039;ve got the CA certificate, now what? */  added crt conversion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers. Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got the following things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file;&lt;br /&gt;
* sign certificates for our own use;&lt;br /&gt;
* distribute the public CA certificate to every machine/person that may need to verify certificates that we&#039;ve signed.&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;br /&gt;
The last point means we need to send out our public CA certificate. In some cases, you can provide others with your &#039;&#039;.pem&#039;&#039; file, but in other cases you&#039;re better off providing a simpler &#039;&#039;.crt&#039;&#039; file. The difference is explained nicely at the [http://info.ssl.com/article.aspx?id=12149 ssl.com site]&lt;br /&gt;
To create a public CA certificate in .crt format you can issue the following command:&lt;br /&gt;
 openssl x509 -outform der -in cacert.pem -out cacert.crt&lt;br /&gt;
By the way, it&#039;s usually better to distribute the public certificate with a more recognizable file name, such as &#039;&#039;saruman.biz.crt&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3090</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3090"/>
		<updated>2016-10-29T19:40:20Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Creating the CA root certificate key pair */  expanded with checks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely&lt;br /&gt;
* &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039;, and&lt;br /&gt;
* &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;.&lt;br /&gt;
NEVER send your private key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command above, that this certificate is obviously a root certificate: it can verify the signature of everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
In the same manner you can inspect your private key:&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -text&lt;br /&gt;
&lt;br /&gt;
Note that this can be used to check if the private key and certificate belong together: the `modulus&#039; and the `public exponent&#039; portions in the private &lt;br /&gt;
key and the certificate must match. But since the public exponent is usually 65537 and it&#039;s bothering comparing long modulus you can use the following approach:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -modulus | openssl md5&lt;br /&gt;
 openssl rsa -in private/cakey.pem -noout -modulus  | openssl md5&lt;br /&gt;
And then compare these really shorter numbers. Both commands will output something like:&lt;br /&gt;
 (stdin)= 96a281eca852b794a907186a9703ddf4&lt;br /&gt;
With overwhelming probability they will differ if the keys are different.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3089</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3089"/>
		<updated>2016-02-23T09:23:28Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: reordered&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file: we&#039;ll need to alter some parameters for the root certificate that are hard-coded in the setup scripts.&lt;br /&gt;
&lt;br /&gt;
We find the scripts in &#039;&#039;/usr/lib/ssl/misc/&#039;&#039;. Note that there are two different scripts:  &#039;&#039;CA.sh&#039;&#039;, a shell script, and &#039;&#039;CA.pl&#039;&#039;, a perl script. Since we&#039;re more into shell scripting than perl programming, we go for the shell script. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039; and &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. NEVER send your public key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command that this certificate is obviously a root certificate: it can sign everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3088</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3088"/>
		<updated>2016-02-23T09:19:31Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Editing the CA.sh script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Actually, you don&#039;t need to use the &#039;&#039;CA.sh&#039;&#039; shell script. There&#039;s also a &#039;&#039;CA.pl&#039;&#039; perl script. However, if you&#039;re more into shell scripting than perl programming, go for the shell script.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, not everything we want to change is actually set from the &#039;&#039;openssl.conf&#039;&#039; file. So we edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:4096&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&lt;br /&gt;
 DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
 CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
 ...&lt;br /&gt;
 echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
 $REQ -new -newkey rsa:4096 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039; and &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. NEVER send your public key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command that this certificate is obviously a root certificate: it can sign everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3087</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3087"/>
		<updated>2016-02-23T09:02:29Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Deciding on CA parameters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates issued ten years ago to just lie around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our home server. Yes, it&#039;s sound advice to keep the root certificate on an offline machine and all that, but this is for a self-signed certificate, and if this particular directory gets compromised, then so is the whole home server, and we&#039;ve got greater issues than the loss of a self-signed private key.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and I happen to live in it.&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Actually, you don&#039;t need to use the &#039;&#039;CA.sh&#039;&#039; shell script. There&#039;s also a &#039;&#039;CA.pl&#039;&#039; perl script. However, if you&#039;re more into shell scripting than perl programming, go for the shell script.&lt;br /&gt;
&lt;br /&gt;
Now edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. A little further down, we find the default location &#039;&#039;CATOP=./demoCA&#039;&#039;. Change this (relative) path to the (absolute) path we&#039;ve decided upon. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:2048&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
...&lt;br /&gt;
CATOP=/etc/ssl/ca&lt;br /&gt;
...&lt;br /&gt;
echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
$REQ -new -newkey rsa:2048 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039; and &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. NEVER send your public key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command that this certificate is obviously a root certificate: it can sign everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3086</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3086"/>
		<updated>2016-02-22T12:11:30Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Creating the Certificate Authority (CA) - preparations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed (if not, run &#039;&#039;apt-get install openssl&#039;&#039;). Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates from ten years earlies to wander around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our central server.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accommodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and we live pretty close to it.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Actually, you don&#039;t need to use the &#039;&#039;CA.sh&#039;&#039; shell script. There&#039;s also a &#039;&#039;CA.pl&#039;&#039; perl script. However, if you&#039;re more into shell scripting than perl programming, go for the shell script.&lt;br /&gt;
&lt;br /&gt;
Now edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. A little further down, we find the default location &#039;&#039;CATOP=./demoCA&#039;&#039;. Change this (relative) path to the (absolute) path we&#039;ve decided upon. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:2048&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
...&lt;br /&gt;
CATOP=/etc/ssl/ca&lt;br /&gt;
...&lt;br /&gt;
echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
$REQ -new -newkey rsa:2048 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039; and &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. NEVER send your public key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command that this certificate is obviously a root certificate: it can sign everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3085</id>
		<title>Certificate fundamentals</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Certificate_fundamentals&amp;diff=3085"/>
		<updated>2016-02-22T12:06:31Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Deciding on CA parameters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Certificates, an introduction==&lt;br /&gt;
Digital certificates are an extremely important means to identify identities (of users, as well as of servers) on the Internet, or indeed on most any network. For instance, we use them to encrypt network traffic when we use the HTTPS protocol. Thus, we really need certificates.&lt;br /&gt;
&lt;br /&gt;
Now, as [http://www.debian-administration.org/articles/618 this article] explains, you can either buy your certificates from a certificate authority like [http://www.verisign.com/ VeriSign], [http://www.thawte.com/ Thawte] or [http://www.equifaxsecure.co.uk/index.html Equifax Secure], but these certificates cost more than a couple of Euro&#039;s, and also need to be renewed (usually every year). So the other route, the one we&#039;ll be taking, is to create our own Certificate Authority (CA), and use that to sign certificates for our needs (secure webserver, secure mailserver etcetera).&lt;br /&gt;
&lt;br /&gt;
Now, &amp;quot;creating a CA&amp;quot; sounds like grave installation and configuration work, but in fact a CA does not have to be an actual service, demon or program. A CA is more like a concept, at the heart of which lies the CA &amp;quot;root certificate&amp;quot;. So if we obtain a little set of tools and generate our own root certificate, then we&#039;re in business.&lt;br /&gt;
&lt;br /&gt;
==Creating the Certificate Authority (CA) - preparations==&lt;br /&gt;
To generate the root CA for our own little organization, we first need tools. These tools under Debian come with the OpenSSL software - which you&#039;ll usually find already installed. Now to generate the CA root certificate, we&#039;ll use a shell script from the OpenSSL package: &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;, which together with the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; can create our CA root certificate. To that end, we&#039;ll first need to decide on some parameters.&lt;br /&gt;
&lt;br /&gt;
===Deciding on CA parameters===&lt;br /&gt;
&#039;&#039;&#039;How strong&#039;&#039;&#039; do we want our root certificate? 1024 bits is the default, but the stronger, the better. We suggest 4096 bits - not because 2048 isn&#039;t sufficient (even 1024 is still very very good, even in the year 2016), but because it&#039;s not necessary to keep a CA&#039;s key length very low, and 4096 can be expected to remain pretty secure until after 2030 (see [http://danielpocock.com/rsa-key-sizes-2048-or-4096-bits here]).&lt;br /&gt;
&lt;br /&gt;
How long should our &#039;&#039;&#039;CA root certificate remain valid&#039;&#039;&#039;? The longer, the more convenient - but maybe some day in the future, you feel you don&#039;t want certificates from ten years earlies to wander around, expired but otherwise valid. Expiry of the root certificate that goes along with that certificate might help you. So what&#039;s an appropriate time for your root CA? That depends. For our home CA, we use 15 years. For a business, the cost of providing new root certificates to all computers, employees, and maybe customers, can be so high that you&#039;d rather have 25 years - or maybe security is paramount, and 5 years is long enough for you. We can&#039;t say - but our home CA&#039;s use 15 years, because we feel that that&#039;s a nice intermediate value. 15 years, including about 4 leap days, comes to 5479 days.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Where do we want to store&#039;&#039;&#039; our CA root certificate? By default, the &#039;&#039;CA.sh&#039;&#039; script feels it must store all generated certificates in &#039;&#039;./demoCA&#039;&#039;. That&#039;s not very handy for us. We rather have a central location like &#039;&#039;/etc/ssl/ca&#039;&#039; on our central server.&lt;br /&gt;
&lt;br /&gt;
How long should &#039;&#039;&#039;any generated certificate be valid&#039;&#039;&#039;? The default value that the &#039;&#039;CA.sh&#039;&#039; script provides is one year. We find that enough - although we add 7 days to accomodate some overlap when having to regenerate the certificate upon nearing the expiry date (note: we really want to replace certificates &#039;&#039;prior&#039;&#039; to expiry :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What &amp;quot;company&amp;quot; data&#039;&#039;&#039; will we enter in the certificate? Several fields must be entered, some of which you could fill out at will. However, it&#039;s not exactly clear why you would want to confuse people trying to authenticate you, your webserver or some other connection by filling out, for example, the country with an incorrect or even non-existent code. On the other hand, you can keep your own privacy in mind, and not fill in your full name, but rather your website&#039;s name, at the &amp;quot;common name&amp;quot; section of your CA root certificate. Again, this depends on what you&#039;re going to use your CA for. We at [https://www.saruman.biz saruman.biz] decided to use the following values:&lt;br /&gt;
* Organization name: Saruman.biz. We&#039;re private persons, not companies, but we want to maintain a minimum of privacy, so we&#039;ve put this fake entity name here.&lt;br /&gt;
* Province: Utrecht. Yep, that&#039;s a province in the Netherlands, and we live pretty close to it.&lt;br /&gt;
* Country: NL (that&#039;s the Netherlands)&lt;br /&gt;
Maybe you want to provide more default information to your CA setup; just look further down on how to.&lt;br /&gt;
&lt;br /&gt;
So the information we&#039;ve decided upon is like this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Parameter&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|value&lt;br /&gt;
|-&lt;br /&gt;
|root certificate encryption&lt;br /&gt;
|4096 bits&lt;br /&gt;
|-&lt;br /&gt;
|root certificate validity&lt;br /&gt;
|5479 days (15 years)&lt;br /&gt;
|-&lt;br /&gt;
|certificate store&lt;br /&gt;
|&#039;&#039;/etc/ssl/ca&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|default certificate validity&lt;br /&gt;
|370 days (1 year)&lt;br /&gt;
|-&lt;br /&gt;
|Organization name&lt;br /&gt;
|Saruman.biz&lt;br /&gt;
|-&lt;br /&gt;
|Certificate province/county name (default)&lt;br /&gt;
|Utrecht&lt;br /&gt;
|-&lt;br /&gt;
|Certificate country name (default)&lt;br /&gt;
|NL&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;CA.sh&#039;&#039; script ===&lt;br /&gt;
Actually, you don&#039;t need to use the &#039;&#039;CA.sh&#039;&#039; shell script. There&#039;s also a &#039;&#039;CA.pl&#039;&#039; perl script. However, if you&#039;re more into shell scripting than perl programming, go for the shell script.&lt;br /&gt;
&lt;br /&gt;
Now edit &#039;&#039;/usr/lib/ssl/misc/CA.sh&#039;&#039;; find the two lines near the top that define the variables &#039;&#039;DAYS&#039;&#039; and &#039;&#039;CADAYS&#039;&#039;, and set these to what we want them to be. A little further down, we find the default location &#039;&#039;CATOP=./demoCA&#039;&#039;. Change this (relative) path to the (absolute) path we&#039;ve decided upon. Then, a lot further down, we find the line that&#039;s responsible for creating the CA root certificate itself, it&#039;s the line that goes &#039;&#039;$REQ -new -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CAREQ&#039;&#039; (well actually it&#039;s split out over two lines). Here, right after &#039;&#039;-new&#039;&#039; we add &#039;&#039;-newkey rsa:2048&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
With all these changes, the three relevant sections in &#039;&#039;CA.sh&#039;&#039; will be changed to something like this: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
DAYS=&amp;quot;-days 370&amp;quot;        # 1 year&lt;br /&gt;
CADAYS=&amp;quot;-days 5479&amp;quot;     # 15 years&lt;br /&gt;
...&lt;br /&gt;
CATOP=/etc/ssl/ca&lt;br /&gt;
...&lt;br /&gt;
echo &amp;quot;Making CA certificate ...&amp;quot;&lt;br /&gt;
$REQ -new -newkey rsa:2048 -keyout ${CATOP}/private/$CAKEY \&lt;br /&gt;
             -out ${CATOP}/$CAREQ&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Editing the &#039;&#039;openssl.cnf&#039;&#039; configuration file===&lt;br /&gt;
When generating certificates, the OpenSSL tools check the configuration file &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039;. It is necessary to match the parameters in there with the choices and changes of the previous sections, and also it&#039;s handy to change some of the default parameters that certificates require upon generation. It&#039;s important to remember that these parameters will be asked every time you generate a certificate, but it&#039;s ofcourse pretty handy if the default value is set for your situation, so you can just hit that big &amp;amp;lt;enter&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
First up, we&#039;ll change the &#039;&#039;dir&#039;&#039; variable in section &#039;&#039;[ CA_default ]&#039;&#039; to match the dir from the &#039;&#039;CA.sh&#039;&#039; script. Then we find &#039;&#039;default_days&#039;&#039; and change it to our default certificate lifetime: 370 days. Furthermore, we find the certificate strengt in the &#039;&#039;[ req ]&#039;&#039; section; we can change it to our preferred value of 2048 bits.&lt;br /&gt;
&lt;br /&gt;
Now we can put in the optional bits: the default values. Not necessary, but handy. We go to section &#039;&#039;[ req_distinguished_name ]&#039;&#039; and fill them in. For this, we again use the table we&#039;ve previously compounded. &lt;br /&gt;
&lt;br /&gt;
So the changes we&#039;ve made will amount to something like this:&lt;br /&gt;
 [ CA_default ]&lt;br /&gt;
 dir             = /etc/ssl/ca&lt;br /&gt;
 ...&lt;br /&gt;
 default_days    = 370&lt;br /&gt;
 ...&lt;br /&gt;
 [ req ]&lt;br /&gt;
 default_bits    = 2048&lt;br /&gt;
 ...&lt;br /&gt;
 [ req_distinguished_name ]&lt;br /&gt;
 0.organizationName_default  = Saruman.biz&lt;br /&gt;
 stateOrProvinceName_default = Utrecht&lt;br /&gt;
 countryName_default         = NL&lt;br /&gt;
Especially the last section is, again, a pretty arbitrary choice. You could choose not to provide customized default answers (in which case you&#039;re stuck with Internet Widgets Pty from Some-State, AU as the default answers). There are more default values in that section of the &#039;&#039;openssl.cnf&#039;&#039; configuration file; go in there and decide what you want.&lt;br /&gt;
&lt;br /&gt;
==the Certificate Authority root certificate==&lt;br /&gt;
Now with the basic information in place, we can go about generating the certificate itself, and putting it to use. Well, actually we&#039;re not going to generate &#039;&#039;one&#039;&#039; certificate, but &#039;&#039;two&#039;&#039;: the public one, that we give out to anyone that might want to check the validity of any certificate that claims to have been issued by the Saruman.biz CA, and the private one, with which we can digitally sign certificates so as to prove that they&#039;re really issued by said Saruman.biz CA. This is also referred to as a &amp;quot;key pair&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Creating the CA root certificate key pair===&lt;br /&gt;
To generate the CA&#039;s public and private root certificate, as root, execute&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newca&lt;br /&gt;
With the defaults set as given above, you still get some questions. One is &amp;quot;CA certificate filename&amp;quot;. This actually requests from you another certificate with which to sign the one we&#039;re creating. However, we&#039;re generating our root certificate, so we leave this empty and just hit &amp;amp;lt;enter&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next question is for the PEM passphrase. Make that a strong passphrase or password, keep it very secret, and &#039;&#039;&#039;don&#039;t forget it!&#039;&#039;&#039; (and DON&#039;T write it on a piece of paper; use something like [http://keepass.info keepass] to store your secret passwords).&lt;br /&gt;
&lt;br /&gt;
For the next set of questions, you probably have filled in some of the defaults. If you want to leave some entry blank, fill in a period (&#039;&#039;&#039;.&#039;&#039;&#039;). You&#039;ll have to provide the country code, province or state, locality (like city; Saruman.biz leaves this empty), Organization Name, Organizational Unit name (again, empty), and finally the Common Name. This last question is pretty important: the name you put in here is the name under which your CA will go for the next 15 years!! So don&#039;t put in a &amp;quot;funny&amp;quot; name, a bland name, or whatever. We put in &amp;quot;Saruman.biz Root CA&amp;quot;, somewhat like official root CA&#039;s like &amp;quot;Equifax Secure Global eBusiness CA-1&amp;quot; or &amp;quot;Macao Post eSignTrust Root Certification Authority&amp;quot;. The script also asks for an email address, which you may or may not provide, a challenge password, and an &amp;quot;optional company name&amp;quot;, both of which you can leave blank because we&#039;re not sending a certificate signing request out to someone else, but signing it ourselves.&amp;lt;br&amp;gt;&lt;br /&gt;
Having provided this information, we&#039;ve actually already created one half of the key pair, namely the private key. It&#039;ll be &#039;&#039;/etc/openssl/ca/private/ca.pem&#039;&#039;, and is protected by our chosen very strong password. However, we now need the public key, self-signed with the private key.&lt;br /&gt;
&lt;br /&gt;
The next step in our CA creation process thus &#039;&#039;again&#039;&#039; asks for the passphrase. Since this is the second step in a two-step process, we again put in the passphrase we&#039;ve already provided. However, now the shellscript uses this to unlock the private key we&#039;ve (already) created, and then use it to sign the public key we&#039;re now creating. However, the passphrase is &#039;&#039;all&#039;&#039; that it asks. It now generates a signing request (&#039;&#039;/etc/openssl/ca/careq.pem&#039;&#039;), then uses the private key to sign it, and then generate the public key, to be found in &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. You can remove &#039;&#039;careq.pem&#039;&#039; after you&#039;ve inspected the &#039;&#039;cacert.pem&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
So now we&#039;ve got two root certificates, namely &#039;&#039;&#039;private&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/private/cakey.pem&#039;&#039; and &#039;&#039;&#039;public&#039;&#039;&#039; key &#039;&#039;/etc/openssl/ca/cacert.pem&#039;&#039;. NEVER send your public key out to ANYONE! Protect that key, and its passphrase, with your life. If you lose the file, lose the passphrase, or the key gets compromised (lost to an unknown party) then you&#039;ve got to replace your root certificates AND you&#039;ll have to re-issue ALL certificates that you&#039;ve ever signed (we&#039;re not going into certificate revocation here).&lt;br /&gt;
&lt;br /&gt;
You can inspect your certificates (when you&#039;re in directory &#039;&#039;/etc/openssl/ca&#039;&#039;) with commands like this:&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -text&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -dates&lt;br /&gt;
 openssl x509 -in cacert.pem -noout -purpose&lt;br /&gt;
Note from the last command that this certificate is obviously a root certificate: it can sign everything but the kitchen sink.&lt;br /&gt;
&lt;br /&gt;
===We&#039;ve got the CA certificate, now what?===&lt;br /&gt;
With the root CA certificates available to us, we&#039;ve got two things to do:&lt;br /&gt;
* guard very carefully the public and (especially) the private key file&lt;br /&gt;
* sign certificates for our own use&lt;br /&gt;
The first means we&#039;ve got to keep a copy of the private key file in some other, safe location, and we&#039;ve got to secure the private key on the server where it sits - both the machine and the file. It might even be wise to remove the private key, and keep it on a USB stick, and only read it when signing certificates.&lt;br /&gt;
The second thing means we&#039;ve got to generate keys for SSL and TLS connections, just as we need them. This is covered in our [[Creating digital certificates with our root certificate | creating digital certificates]] section.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3084</id>
		<title>E-mail server section</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3084"/>
		<updated>2016-02-22T10:35:02Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Inserting data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E-mail server setup==&lt;br /&gt;
What we want to accomplish here is the setup of a mail server with the following properties:&lt;br /&gt;
* can serve multiple mail domains&lt;br /&gt;
* can relay mail for other domains to other mail servers&lt;br /&gt;
* can have one or more mailboxes per domain&lt;br /&gt;
* users of these mailboxes can be virtual (do not need to have a Linux user account)&lt;br /&gt;
* can have multiple aliases per mailbox&lt;br /&gt;
* can forward mail for certain aliases to multiple mailboxes&lt;br /&gt;
For this type of mail server setup, we owe a great thankyou to [https://workaround.org/ispmail/squeeze Christoph Haas], whose advise has helped us create flexible and reliable mail servers since 2003.&lt;br /&gt;
&lt;br /&gt;
==Preparation==&lt;br /&gt;
We&#039;ll assume that the server currently has no mailserver installed, at least no other than the default &#039;&#039;exim&#039;&#039; mailserver. Furthermore, the server is already fitted with MySQL, and this database is running without problems.&lt;br /&gt;
&lt;br /&gt;
The hostname of the server must be set correctly, so that &#039;&#039;hostname -f&#039;&#039; returns a valid DNS name, like &#039;&#039;lighthouse.saruman.biz.&#039;&#039;. It might also be an internal name like &#039;&#039;lighthouse.saruman.lan.&#039;&#039; but that will require us to give extra attention to the name under which Postfix will contact its collegues on the Internet. Also, the server can correctly [Networking_section#DNS_resolution_under_Debian | resolve DNS names] like [http://www.debian.org www.debian.org], preferably by running it&#039;s own caching DNS server.&lt;br /&gt;
&lt;br /&gt;
The server is kept on the correct date and time using NTP, TCP port 25 is open on the server, the ISP will allow connections from Internet to this port, and if there&#039;s a firewall running on this server, then it has port 25 open so as to not block incoming e-mail.&lt;br /&gt;
&lt;br /&gt;
==Software installation==&lt;br /&gt;
As a first step, we use [[APT and aptitude|apt or aptitude]] to make sure that our server is up-to-date. Then we can install the necessary software packages. Under Debian 5.0 &amp;quot;Lenny&amp;quot;, the (single) packages is:&lt;br /&gt;
* &#039;&#039;postfix&#039;&#039;, the mail server itself - this includes the &amp;quot;virtual package&amp;quot; postfix-tls, that we want to use to secure connections to Postfix with the TLS protocol&lt;br /&gt;
At the same time we can - and must - purge the following packages:&lt;br /&gt;
* exim4&lt;br /&gt;
* exim4-base&lt;br /&gt;
* exim4-daemon-light&lt;br /&gt;
* exim4-config&lt;br /&gt;
In &#039;&#039;aptitude&#039;&#039;, only press &amp;quot;go&amp;quot; when you&#039;ve marked all four of these packages &amp;quot;purge&amp;quot;, or you cannot install postfix.&lt;br /&gt;
&lt;br /&gt;
When installing the postfix package, the Debian installer script will ask you several questions, which you can answer like this:&lt;br /&gt;
* General type of mail configuration: Internet site&lt;br /&gt;
* System mail name: the FQDN of the mail server that you&#039;ve verified in the previous section. Note that the script will try to guess the DNS name, but that might yield a DNS name with a trailing dot. That is technically correct, but the installation script will barf. Remove the trailing dot before hitting &amp;amp;lt;enter&amp;gt;!&lt;br /&gt;
* Postmaster mail address: the address that all mail should go to that is addressed to &amp;quot;root&amp;quot; and &amp;quot;postmaster&amp;quot;.&lt;br /&gt;
* Domain list: give the list of all domains that the machine can consider itself the FINAL destination for. This should at a minimum include an empty value, &amp;quot;localhost&amp;quot; and the FQDN of the machine itself (no trailing dots!); however, if you&#039;re running your own mail domain, you can also add that (e.g. &amp;quot;saruman.biz&amp;quot;). Thus, the list could look like this:&lt;br /&gt;
 saruman.biz, lighthouse.saruman.lan, localhost.saruman.lan, , localhost&lt;br /&gt;
* Force synchronous updates? We think that&#039;s not necessary, but please read the question and decide for yourself&lt;br /&gt;
* Local networks: something like &#039;&#039;127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.67.0/24&#039;&#039; (the default, augmented with your local IP range)&lt;br /&gt;
* Mailbox size limits: you can give postfix a limit in bytes, but we&#039;re going to use one single big mailbox for all users, so we cannot let Postfix guard it. Leave it at 0 (zero) so we don&#039;t have a size limit.&lt;br /&gt;
* Character for local address extension: we leave it at &#039;&#039;+&#039;&#039;&lt;br /&gt;
* Internet protocols to use: currently we don&#039;t have IPv6 support, so there&#039;s no sense in letting Postfix try to serve IPv6. We choose &#039;&#039;ipv4&#039;&#039; only.&lt;br /&gt;
With the above data, the Debian install script for Postfix can do its job and configure Postfix with some basic settings.&lt;br /&gt;
&lt;br /&gt;
Now that Postfix is installed, we can install some dependent packages (we could install them in the same run, but if anything goes amiss with the postfix installation, then these packages are going to remain unconfigured as well):&lt;br /&gt;
* &#039;&#039;postfix-doc&#039;&#039;, the accompanying documentation;&lt;br /&gt;
* &#039;&#039;postfix-mysql&#039;&#039;, necessary to have Postfix talk to our MySQL server;&lt;br /&gt;
* &#039;&#039;postfix-pcre&#039;&#039; to be able to parse regular expressions, which which we can combat spam;&lt;br /&gt;
* &#039;&#039;dovecot-imapd&#039;&#039; is a daemon that will provide your users with IMAP access to their mail;&lt;br /&gt;
* &#039;&#039;dovecot-pop3d&#039;&#039; is another daemon, but for the POP3 protocol.&lt;br /&gt;
&lt;br /&gt;
==Virtual Mailman creation==&lt;br /&gt;
When we&#039;re done, we&#039;ll need a &amp;quot;system user&amp;quot;, a sort of virtual mailman that is the owner of all mailboxes that we&#039;re serving. We suggest the name &amp;quot;vmail&amp;quot; for this user. Note: this user does not get his own mailbox (i.e. there&#039;s no mailbox at vmail@saruman.biz).&lt;br /&gt;
&lt;br /&gt;
To create this user, and his home directory, we can run the following commands:&lt;br /&gt;
 groupadd -g 120 vmail&lt;br /&gt;
 useradd -g vmail -u 120 vmail -d /data/vmail -m -s /bin/false&lt;br /&gt;
As you see, we&#039;ve chosen a group ID and user ID of 120 (after confirming that this ID was not taken by another group or user, by checking &#039;&#039;/etc/passwd&#039;&#039; and &#039;&#039;/etc/group&#039;&#039;. Furthermore, we&#039;ve decided to keep the &#039;&#039;vmail&#039;&#039; user&#039;s home directory not under &#039;&#039;/home/vmail&#039;&#039;, but in a special place where we&#039;re going to expect server data to reside - in our server, the &#039;&#039;/data&#039;&#039; directory (which is a RAID-5 array mounted under root). By adding &#039;&#039;-m&#039;&#039;, we&#039;ve actually created the home directory, and adding &#039;&#039;-s /bin/false&#039;&#039; makes totally sure that the user &#039;&#039;vmail&#039;&#039; can never ever log in - even if we&#039;ve not created a password for this user, so &#039;&#039;vmail&#039;&#039; shouldn&#039;t be able to log in anyway. Better safe than sorry.&lt;br /&gt;
&lt;br /&gt;
To tell Postfix that this &#039;&#039;vmail&#039;&#039; user is someone special, we run&lt;br /&gt;
 postconf -e virtual_uid_maps=static:120&lt;br /&gt;
 postconf -e virtual_gid_maps=static:120&lt;br /&gt;
That makes postfix understand that all mail for the virtual mail domains must be written to disk with these specified user and group ID&#039;s.&lt;br /&gt;
&lt;br /&gt;
==MySQL configuration==&lt;br /&gt;
&lt;br /&gt;
===Database preparation===&lt;br /&gt;
We will use the MySQL database to record data on our mail system, and then give our Postfix access to this database so that it can read its configuration from there. For starters, we&#039;ll create a MySQL database named &amp;quot;vmail&amp;quot;, and a MySQL user named &amp;quot;vmail_admin&amp;quot; that can read all necessary data from that &amp;quot;vmail&amp;quot; database. Then, we create the necessary tables, and a view that links these tables. We do this with the MySQL client &#039;&#039;mysql&#039;&#039;. However, we&#039;re quite lazy, so we don&#039;t create this database by hand (that&#039;s error-prone), but by use of a script [[create.vmail.sql]]. To this end, feed the [[create.vmail.sql]] script into the &#039;&#039;mysql&#039;&#039; client like this:&lt;br /&gt;
 mysql -u root -p &amp;lt; create.vmail.sql&lt;br /&gt;
(This of course assumes you have &#039;&#039;create.vmail.sql&#039;&#039; in your current working directory; if not you can include the path to the file.) Simply give the MySQL root user password, and the script creates the database, the user, the necessary tables, and the view.&amp;lt;br&amp;gt;&lt;br /&gt;
A note of caution: it is never a good idea to just run scripts without a proper understanding of what it does. Especially with MySQL, it will be advantageous if you understand the SQL commands. Open the script in a text editor, open the [http://dev.mysql.com/doc/refman/5.0/en/ MySQL command reference], and trace back what the script does exactly.&lt;br /&gt;
&lt;br /&gt;
===Inserting data===&lt;br /&gt;
Next up, we fill the database with the first sets of values (either test data or the first of our production data). We&#039;ll start off with the virtual domains that we&#039;re hosting, by running the mysql client and feeding it information like this:&lt;br /&gt;
 mysql -u root -p vmail&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (id, vdomain) VALUES (1, &#039;saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;wiki.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;shop.saruman.biz&#039;);&lt;br /&gt;
This has the effect of creating three entries. You can check that everything worked as planned by executing&lt;br /&gt;
 mysql&amp;gt; select * from virtual_domains;&lt;br /&gt;
Note: only the first entry needs an &#039;&#039;id&#039;&#039; value, because in MySQL we&#039;ve defined that field as AUTO_INCREMENT. After creating your first virtual domain in the table, you never have to use a statement like the first INSERT again, only statements like the other two.&lt;br /&gt;
&lt;br /&gt;
Now the MySQL database has the information needed by Postfix to recognise that you have three virtual mail domains (namely the three domains in the VALUES section) for which it hosts virtual mailboxes. Postfix cannot read this information yet, but that&#039;ll be taken care of in the next section.&lt;br /&gt;
&lt;br /&gt;
Whle still within the mysql client, we can now create users:&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (id, domain_id, user, passwd) VALUES (1, 1, &#039;jan&#039;, MD5(&#039;JanSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (1, &#039;mike&#039;, MD5(&#039;MikeSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (3, &#039;shopkeeper&#039;, MD5(&#039;ShopSecret&#039;));&lt;br /&gt;
This has the effect of creating three users &amp;quot;jan&amp;quot; (in domain saruman.biz), &amp;quot;mike&amp;quot; (in domain saruman.biz) and &amp;quot;shopkeeper&amp;quot; (in domain shop.saruman.biz). Again, the &#039;&#039;id&#039;&#039; value is only ever needed in the first statement, because from now on every user addition will auto-increment &#039;&#039;id&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The passwords shown are encrypted with MD5, and put in the &#039;&#039;passwd&#039;&#039; field. Later on, the users will be able to access their mailboxes using this password; we won&#039;t tell Postfix anything about them, because it doesn&#039;t need the passwords. You can check the content of the &#039;&#039;virtual_users&#039;&#039; table with the right &amp;quot;select&amp;quot; statement, and you can now also see that the view &#039;&#039;view-users&#039;&#039; works:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_users;&lt;br /&gt;
 mysql&amp;gt; select * from view_users;&lt;br /&gt;
&lt;br /&gt;
Should you need to update a user&#039;s password from the command line, you can use the following command, provided you&#039;ve looked up that user&#039;s &#039;&#039;id&#039;&#039; :&lt;br /&gt;
 UPDATE virtual_users set passwd = MD5(&#039;&amp;lt;password&amp;gt;&#039;) WHERE id = &#039;&amp;lt;id&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;re going to add some aliases, which are alternative e-mail addresses for the users; their primary e-mail address can already be seen in the &#039;&#039;view_users&#039;&#039; view, but perhaps you also want mail to &amp;quot;webmaster@shop.saruman.biz&amp;quot; to arrive at one or more mailboxes, e.g. in the mailbox for user &amp;quot;shopkeeper&amp;quot; (within domain &amp;quot;shop.saruman.biz&amp;quot;) and this guy&#039;s home address (&amp;quot;j.doe@example.com&amp;quot;). Furthermore, we&#039;ll define catchall-addresses for all domains, that&#039;ll send all mail for which no mailbox can be found to the mailbox of user Mike (for the first two domains) and Webmaster (for shop.saruman.biz; Webmaster himself is an alias yet again, that points to shopkeeper@shop.saruman.biz). To create the catchall, leave out a value for the source address. This creates the empty value for source that will be expanded (using source@domain) to &amp;quot;@domain&amp;quot;.&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (id, domain_id, source, destination)&lt;br /&gt;
        VALUES (1, 2, &#039;webmaster&#039;, &#039;shopkeeper@shop.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, source, destination)&lt;br /&gt;
        VALUES (2, &#039;webmaster&#039;, &#039;j.doe@example.com&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (1, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (2, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (3, &#039;webmaster@saruman.biz&#039;);&lt;br /&gt;
 &lt;br /&gt;
Again, we don&#039;t need to add the &#039;&#039;id&#039;&#039; value any more after the first ever insertion into this table.&lt;br /&gt;
&lt;br /&gt;
We can check the result by running a select statement against the &#039;&#039;virtual_aliases&#039;&#039; table and &#039;&#039;view_aliases&#039;&#039; view:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_aliases;&lt;br /&gt;
 mysql&amp;gt; select * from view_aliases;&lt;br /&gt;
&lt;br /&gt;
== Postfix configuration for MySQL lookups==&lt;br /&gt;
Next, we&#039;re going to tell Postfix to use the &#039;&#039;vmail&#039;&#039; database, and also how to read the database (Postfix never writes the MySQL database). To this end, we&#039;re going to create three configuration files in directory &#039;&#039;/etc/postfix&#039;&#039;. We&#039;ll start off with one configuration file, with which Postfix can determine if a domain name is among the domain(s) that it&#039;s actually hosting mailboxes for. Then we&#039;ll create the config file that checks the table that contains all the users that have a virtual mailbox, and finally we create the lookup for the table with all the aliases.&lt;br /&gt;
&lt;br /&gt;
===Virtual mail domains lookup===&lt;br /&gt;
&lt;br /&gt;
Create file &#039;&#039;/etc/postfix/mysql-virtual-domains.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM virtual_domains WHERE vdomain=&#039;%s&#039;&lt;br /&gt;
Next, we tell postfix to check this configuration file when it needs to check &amp;quot;virtual_mailbox_domains&amp;quot;:&lt;br /&gt;
 postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
Use of this configuration file in postfix has the effect of returning &amp;quot;yes&amp;quot; when checking our database for the domain part of an email address. Naturally, this configuration file has to be fitted with the actual &#039;&#039;vmail_admin&#039;&#039; password rather than our example &amp;quot;SuperSecret&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Virtual mail user lookup===&lt;br /&gt;
Create the file &#039;&#039;/etc/postfix/mysql-virtual-mailbox-maps.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
Next, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_mailbox_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
The lookup of virtual mailboxes should work with the data we&#039;ve put into the database previously. i.e.&lt;br /&gt;
 postmap -q jan@saruman.biz mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
should return a &#039;&#039;&#039;1&#039;&#039;&#039; to acknowledge that &amp;quot;jan@saruman.biz&amp;quot; is indeed a virtual mailbox in our Postfix configuration.&lt;br /&gt;
&lt;br /&gt;
=== Virtual alias lookup===&lt;br /&gt;
Create another cf file at &#039;&#039;/etc/postfix/mysql-virtual-alias-maps.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT destination FROM view_aliases WHERE email=&#039;%s&#039;&lt;br /&gt;
And create yet another cf file at &#039;&#039;/etc/postfix/mysql-email2email.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT email FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
&lt;br /&gt;
Again, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_alias_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf&lt;br /&gt;
The lookup of virtual aliases should now work as designed:&lt;br /&gt;
 postmap -q shopkeeper@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
 postmap -q webmaster@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
If you&#039;ve put in the data from the previous section, then both commands should return the same result: &#039;&#039;shopkeeper@saruman.biz&#039;&#039;. This shows that Postfix will deliver  mail to shopkeeper or to webmaster to the mailbox of shopkeeper.&lt;br /&gt;
&lt;br /&gt;
===Finishing up configuration files===&lt;br /&gt;
When everything works as planned, then we secure the configuration files against prying eyes. Remember, the configuration files contain the user/password combination which which to access the &#039;&#039;vmail&#039;&#039; SQL database. The &#039;&#039;vmail_admin&#039;&#039; user has only read rights, and passwords in there are encrypted, but nevertheless, this is information we need to protect. Thus:&lt;br /&gt;
 chown root:postfix /etc/postfix/mysql-*.cf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/postfix/mysql-*.cf&lt;br /&gt;
This protects all four configuration files since only root can write them, members of group &#039;&#039;postfix&#039;&#039; can read them, and the rest of the world cannot access them at all.&lt;br /&gt;
&lt;br /&gt;
==Configuring mail delivery through Dovecot LDA==&lt;br /&gt;
E-mails get delivered to the virtual mailboxes by means of a Mail Delivery Agent (MDA). With Postfix, the standard MDA for delivery to virtual mailboxes is called &#039;&#039;virtual&#039;&#039;, but we&#039;re not going to use that; we&#039;re going to use &#039;&#039;[http://wiki.dovecot.org/LDA Dovecot LDA]&#039;&#039;, which is a program called &#039;&#039;deliver&#039;&#039;. By the way, the abbreviation LDA stands for Local Delivery Agent, which of course means more or less the same as MDA.&lt;br /&gt;
===Enabling the Dovecot daemon===&lt;br /&gt;
To make Postfix use Dovecot LDA, we add the following line to &#039;&#039;/etc/postfix/master.cf&#039;&#039;:&lt;br /&gt;
 dovecot   unix  -       n       n       -       -       pipe&lt;br /&gt;
     flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}&lt;br /&gt;
This declares the service &amp;quot;dovecot&amp;quot; to mean using the program &#039;&#039;/usr/lib/dovecot/deliver&#039;&#039; with the right parameters. If we now let Postfix reload its files, it&#039;ll learn about this new service. Subsequently we can instruct Postfix to start using it, by declaring service &amp;quot;dovecot&amp;quot; to be the virtual transport of choice, and specifying one Dovecot-specific variable:&lt;br /&gt;
 postfix reload&lt;br /&gt;
 postconf -e virtual_transport=dovecot&lt;br /&gt;
 postconf -e dovecot_destination_recipient_limit=1&lt;br /&gt;
===Dovecot default configuration===&lt;br /&gt;
Now to configure Dovecot itself: open &#039;&#039;/etc/dovecot/dovecot.conf&#039;&#039; with your favourite editor [[vim]]; first make sure the &#039;&#039;protocols =&#039;&#039; line reads&lt;br /&gt;
 protocols = imap imaps pop3 pop3s&lt;br /&gt;
(which it should by default). The second setting is quite crucial. By default, the location of the mail directories is found automatically by Dovecot, but here that won&#039;t work. Find the line that reads &#039;&#039;#mail_location =&#039;&#039;, and change it to&lt;br /&gt;
 mail_location = maildir:/data/vmail/%d/%n/Maildir&lt;br /&gt;
This will look for mail in directory &#039;&#039;/data/vmail/&#039;&#039;&#039;DOMAIN&#039;&#039;&#039;/&#039;&#039;&#039;USER&#039;&#039;&#039;/Maildir&#039;&#039;, and expect this directory to be in &amp;quot;maildir&amp;quot; format.&lt;br /&gt;
Next look for a section called &amp;quot;auth default&amp;quot;. First define the allowed authentication mechanisms:&lt;br /&gt;
 mechanisms = plain login&lt;br /&gt;
Then inside that same section you need to uncomment:&lt;br /&gt;
 passdb sql {&lt;br /&gt;
     args = /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 }&lt;br /&gt;
which tells Dovecot that the passwords are stored in an SQL database (it&#039;s obvious that we&#039;ll now have to create this conf-file) and:&lt;br /&gt;
 userdb static {&lt;br /&gt;
     args = uid=120 gid=120 home=/data/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
to tell Dovecot where the mailboxes are located. This is similar to the &#039;&#039;mail_location&#039;&#039; setting. Next task: comment out the section &#039;&#039;passdb pam&#039;&#039;, so that Dovecot doesn&#039;t accidentally try to service local users as well.&lt;br /&gt;
&lt;br /&gt;
Next up: tell Dovecot to handle IMAP the same as previous versions of this virtual mailserver have - this can prove to be quite tricky if you already have mailboxes full of mail, put there by e.g. Courier-IMAP. What works for us, is&lt;br /&gt;
 namespace private {&lt;br /&gt;
     separator = .&lt;br /&gt;
     prefix = &lt;br /&gt;
     inbox = yes&lt;br /&gt;
 }&lt;br /&gt;
However, your mileage may vary.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to comment out the &#039;&#039;passdb pam&#039;&#039; sections, since we&#039;re not hosting mail for local users.&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;ll edit the section &#039;&#039;socket listen&#039;&#039; so that Dovecot can access the user database (master section), and our Postfix mailserver can access Dovecot (client section):&lt;br /&gt;
 socket listen {&lt;br /&gt;
   master {&lt;br /&gt;
     path = /var/run/dovecot/auth-master&lt;br /&gt;
     mode = 0600&lt;br /&gt;
     user = vmail&lt;br /&gt;
   }&lt;br /&gt;
   client {&lt;br /&gt;
     path = /var/spool/postfix/private/auth&lt;br /&gt;
     mode = 0660&lt;br /&gt;
     user = postfix&lt;br /&gt;
     group = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Finally, the protocol section, where we specify log files, an address to put in mails when we send out nondelivery reports, and a place to store scripts:&lt;br /&gt;
 protocol lda {&lt;br /&gt;
     log_path = /var/log/appslog/mail/dovecot-deliver.log&lt;br /&gt;
     auth_socket_path = /var/run/dovecot/auth-master&lt;br /&gt;
     postmaster_address = postmaster@saruman.biz&lt;br /&gt;
     mail_plugins = cmusieve&lt;br /&gt;
     global_script_path = /data/vmail/globalsieverc&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You could change the log path to &amp;quot;log_path =&amp;quot; With a empty logpath syslog will log the events. &lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve finished the Dovecot configuration file, we need to create a fitting MySQL configuration file for Dovecot. The file is &#039;&#039;/etc/dovecot/dovecot-sql.conf&#039;&#039;, and its contents are&lt;br /&gt;
 driver = mysql&lt;br /&gt;
 connect = host=127.0.0.1 dbname=vmail user=vmail_admin password=SuperSecret&lt;br /&gt;
 default_pass_scheme = PLAIN-MD5&lt;br /&gt;
 password_query = SELECT email as user, passwd as password FROM view_users WHERE email=&#039;%u&#039;;&lt;br /&gt;
When you&#039;ve created this file (as root), change the attributes of &#039;&#039;dovecot-sql.conf&#039;&#039; and &#039;&#039;dovecot.conf&#039;&#039;, and then restart Dovecot to start using the new configuration. Note: &#039;&#039;dovecot.conf&#039;&#039; needs to be read by Postfix, hence the group ownership for the file.&lt;br /&gt;
 chmod u=rw,g=,o= /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 chgrp vmail /etc/dovecot/dovecot.conf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/dovecot/dovecot.conf&lt;br /&gt;
 /etc/init.d/dovecot restart&lt;br /&gt;
&lt;br /&gt;
To get some more logging in the case something goes wrong. Uncomment the folling and change to yes.&lt;br /&gt;
 auth_verbose = yes&lt;br /&gt;
 auth_debug = yes&lt;br /&gt;
 auth_debug_passwords = yes&lt;br /&gt;
&lt;br /&gt;
===Dovecot SSL configuration===&lt;br /&gt;
Out of the (Debian) box, Dovecot is SSL-enabled. We&#039;ll now replace the generic SSL-certificate, generated for the host by the Dovecot installation script, by our own certificate. To ths end, we first [[Creating_digital_certificates_with_our_root_certificate | generate an appropriate certificate]], e.g. an SSL wildcard certificate: &amp;quot;*.saruman.biz&amp;quot;. This results in a public and a private certificate, both of which must be placed somewhere where Dovecot expects them and can read them.&lt;br /&gt;
&lt;br /&gt;
By default, Dovecot expects the following locations/filenames/owner/attributes:&lt;br /&gt;
 /etc/ssl/certs/dovecot.pem    -rw-r--r--  root:dovecot  4624 bytes&lt;br /&gt;
 /etc/ssl/private/dovecot.pem  -rw-------  root:dovecot  1743 bytes&lt;br /&gt;
If we may make a suggestion: rename the generated certificates in both locations to dovecot.pem.bak, place your generated certificates in their place, and set the owner/permissions like displayed here.&lt;br /&gt;
&lt;br /&gt;
However, if you&#039;ve generated your own keys, you might have used a passphrase on the private key. You&#039;ll have to tell dovecot about it in its configuration file /etc/dovecot/dovecot.conf. To this end, edit the corresponding section by uncommenting the &amp;quot;ssl_&amp;quot; lines, and using your private key password (e.g. &amp;quot;zM7Ertq12&amp;quot;) in the appropriate line:&lt;br /&gt;
 ssl_cert_file = /etc/ssl/certs/dovecot.pem&lt;br /&gt;
 ssl_key_file = /etc/ssl/private/dovecot.pem&lt;br /&gt;
 &lt;br /&gt;
 # If key file is password protected, give the password here. Alternatively&lt;br /&gt;
 # give it when starting dovecot with -p parameter.&lt;br /&gt;
 ssl_key_password = zM7Ertq12&lt;br /&gt;
Naturally you are free to place the keys in a different location, and/or use a different name...&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
&lt;br /&gt;
This is a good moment to test your configuration, if you haven&#039;t been able to test your work inbetween. If everything works as expected, you can add bells and whistles to your configuration.&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;smtpd&#039;&#039; TLS encryption===&lt;br /&gt;
The first addition we&#039;d like to present covers the way Postfix handles incoming connections. Since authentication works, we can have Postfix distrust every (unauthenticated) connection:&lt;br /&gt;
 postconf -e mynetworks=&lt;br /&gt;
Furthermore, since a default SSL certificate is installed by the Debian Postfix installation routine, we can encrypt all our connections using TLS; we enforce this using&lt;br /&gt;
 postconf -e smtpd_use_tls=yes&lt;br /&gt;
 postconf -e smtpd_tls_auth_only=yes&lt;br /&gt;
Of course, you need to adjust the settings of your IMAP client so that it properly uses TLS and properly authenticates itself.&lt;br /&gt;
&lt;br /&gt;
If TLS works, you&#039;ll probably want to change the certificate as you have for Dovecot in the previous section. This is again pretty easy. If you haven&#039;t yet, now is the time to [[Creating_digital_certificates_with_our_root_certificate | creating that custom SSL certificate]] for our mail server - but you have to make sure that you DON&#039;T use a password on the private key. Unlike Dovecot, Postfix cannot be told the password to the private key somewhere.&lt;br /&gt;
&lt;br /&gt;
For starters, look at the TLS-section of your &#039;&#039;main.cf&#039;&#039; that you currently have. Chances are a big chunk of it looks like this:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Now all you need to do is replace the name of the snakeoil-keys with those of appropriate ssl-certificates, the private key of which needs to be NOT passphrase-protected. For this you could copy the Dovecot certificates, if you strip that passphrase in the manner described in the [[Creating_digital_certificates_with_our_root_certificate#Creating_an_SSL_certificate | SSL certificate section]]. The &#039;&#039;main.cf&#039;&#039; then would become:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/postfix.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/postfix.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Restart Postfix, and presto.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other additions ===&lt;br /&gt;
If everything &#039;&#039;still&#039;&#039; works after these changes, then congratulations, you now have a powerful, flexible and pretty secure mail setup. Of course, there are always points for improvements. We&#039;ll cover these in separate pages. One page that we want to direct you to now, is&lt;br /&gt;
* [[Antispam measures]] for our Postfix mailserver&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3083</id>
		<title>E-mail server section</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3083"/>
		<updated>2016-02-22T10:32:40Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Inserting data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E-mail server setup==&lt;br /&gt;
What we want to accomplish here is the setup of a mail server with the following properties:&lt;br /&gt;
* can serve multiple mail domains&lt;br /&gt;
* can relay mail for other domains to other mail servers&lt;br /&gt;
* can have one or more mailboxes per domain&lt;br /&gt;
* users of these mailboxes can be virtual (do not need to have a Linux user account)&lt;br /&gt;
* can have multiple aliases per mailbox&lt;br /&gt;
* can forward mail for certain aliases to multiple mailboxes&lt;br /&gt;
For this type of mail server setup, we owe a great thankyou to [https://workaround.org/ispmail/squeeze Christoph Haas], whose advise has helped us create flexible and reliable mail servers since 2003.&lt;br /&gt;
&lt;br /&gt;
==Preparation==&lt;br /&gt;
We&#039;ll assume that the server currently has no mailserver installed, at least no other than the default &#039;&#039;exim&#039;&#039; mailserver. Furthermore, the server is already fitted with MySQL, and this database is running without problems.&lt;br /&gt;
&lt;br /&gt;
The hostname of the server must be set correctly, so that &#039;&#039;hostname -f&#039;&#039; returns a valid DNS name, like &#039;&#039;lighthouse.saruman.biz.&#039;&#039;. It might also be an internal name like &#039;&#039;lighthouse.saruman.lan.&#039;&#039; but that will require us to give extra attention to the name under which Postfix will contact its collegues on the Internet. Also, the server can correctly [Networking_section#DNS_resolution_under_Debian | resolve DNS names] like [http://www.debian.org www.debian.org], preferably by running it&#039;s own caching DNS server.&lt;br /&gt;
&lt;br /&gt;
The server is kept on the correct date and time using NTP, TCP port 25 is open on the server, the ISP will allow connections from Internet to this port, and if there&#039;s a firewall running on this server, then it has port 25 open so as to not block incoming e-mail.&lt;br /&gt;
&lt;br /&gt;
==Software installation==&lt;br /&gt;
As a first step, we use [[APT and aptitude|apt or aptitude]] to make sure that our server is up-to-date. Then we can install the necessary software packages. Under Debian 5.0 &amp;quot;Lenny&amp;quot;, the (single) packages is:&lt;br /&gt;
* &#039;&#039;postfix&#039;&#039;, the mail server itself - this includes the &amp;quot;virtual package&amp;quot; postfix-tls, that we want to use to secure connections to Postfix with the TLS protocol&lt;br /&gt;
At the same time we can - and must - purge the following packages:&lt;br /&gt;
* exim4&lt;br /&gt;
* exim4-base&lt;br /&gt;
* exim4-daemon-light&lt;br /&gt;
* exim4-config&lt;br /&gt;
In &#039;&#039;aptitude&#039;&#039;, only press &amp;quot;go&amp;quot; when you&#039;ve marked all four of these packages &amp;quot;purge&amp;quot;, or you cannot install postfix.&lt;br /&gt;
&lt;br /&gt;
When installing the postfix package, the Debian installer script will ask you several questions, which you can answer like this:&lt;br /&gt;
* General type of mail configuration: Internet site&lt;br /&gt;
* System mail name: the FQDN of the mail server that you&#039;ve verified in the previous section. Note that the script will try to guess the DNS name, but that might yield a DNS name with a trailing dot. That is technically correct, but the installation script will barf. Remove the trailing dot before hitting &amp;amp;lt;enter&amp;gt;!&lt;br /&gt;
* Postmaster mail address: the address that all mail should go to that is addressed to &amp;quot;root&amp;quot; and &amp;quot;postmaster&amp;quot;.&lt;br /&gt;
* Domain list: give the list of all domains that the machine can consider itself the FINAL destination for. This should at a minimum include an empty value, &amp;quot;localhost&amp;quot; and the FQDN of the machine itself (no trailing dots!); however, if you&#039;re running your own mail domain, you can also add that (e.g. &amp;quot;saruman.biz&amp;quot;). Thus, the list could look like this:&lt;br /&gt;
 saruman.biz, lighthouse.saruman.lan, localhost.saruman.lan, , localhost&lt;br /&gt;
* Force synchronous updates? We think that&#039;s not necessary, but please read the question and decide for yourself&lt;br /&gt;
* Local networks: something like &#039;&#039;127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.67.0/24&#039;&#039; (the default, augmented with your local IP range)&lt;br /&gt;
* Mailbox size limits: you can give postfix a limit in bytes, but we&#039;re going to use one single big mailbox for all users, so we cannot let Postfix guard it. Leave it at 0 (zero) so we don&#039;t have a size limit.&lt;br /&gt;
* Character for local address extension: we leave it at &#039;&#039;+&#039;&#039;&lt;br /&gt;
* Internet protocols to use: currently we don&#039;t have IPv6 support, so there&#039;s no sense in letting Postfix try to serve IPv6. We choose &#039;&#039;ipv4&#039;&#039; only.&lt;br /&gt;
With the above data, the Debian install script for Postfix can do its job and configure Postfix with some basic settings.&lt;br /&gt;
&lt;br /&gt;
Now that Postfix is installed, we can install some dependent packages (we could install them in the same run, but if anything goes amiss with the postfix installation, then these packages are going to remain unconfigured as well):&lt;br /&gt;
* &#039;&#039;postfix-doc&#039;&#039;, the accompanying documentation;&lt;br /&gt;
* &#039;&#039;postfix-mysql&#039;&#039;, necessary to have Postfix talk to our MySQL server;&lt;br /&gt;
* &#039;&#039;postfix-pcre&#039;&#039; to be able to parse regular expressions, which which we can combat spam;&lt;br /&gt;
* &#039;&#039;dovecot-imapd&#039;&#039; is a daemon that will provide your users with IMAP access to their mail;&lt;br /&gt;
* &#039;&#039;dovecot-pop3d&#039;&#039; is another daemon, but for the POP3 protocol.&lt;br /&gt;
&lt;br /&gt;
==Virtual Mailman creation==&lt;br /&gt;
When we&#039;re done, we&#039;ll need a &amp;quot;system user&amp;quot;, a sort of virtual mailman that is the owner of all mailboxes that we&#039;re serving. We suggest the name &amp;quot;vmail&amp;quot; for this user. Note: this user does not get his own mailbox (i.e. there&#039;s no mailbox at vmail@saruman.biz).&lt;br /&gt;
&lt;br /&gt;
To create this user, and his home directory, we can run the following commands:&lt;br /&gt;
 groupadd -g 120 vmail&lt;br /&gt;
 useradd -g vmail -u 120 vmail -d /data/vmail -m -s /bin/false&lt;br /&gt;
As you see, we&#039;ve chosen a group ID and user ID of 120 (after confirming that this ID was not taken by another group or user, by checking &#039;&#039;/etc/passwd&#039;&#039; and &#039;&#039;/etc/group&#039;&#039;. Furthermore, we&#039;ve decided to keep the &#039;&#039;vmail&#039;&#039; user&#039;s home directory not under &#039;&#039;/home/vmail&#039;&#039;, but in a special place where we&#039;re going to expect server data to reside - in our server, the &#039;&#039;/data&#039;&#039; directory (which is a RAID-5 array mounted under root). By adding &#039;&#039;-m&#039;&#039;, we&#039;ve actually created the home directory, and adding &#039;&#039;-s /bin/false&#039;&#039; makes totally sure that the user &#039;&#039;vmail&#039;&#039; can never ever log in - even if we&#039;ve not created a password for this user, so &#039;&#039;vmail&#039;&#039; shouldn&#039;t be able to log in anyway. Better safe than sorry.&lt;br /&gt;
&lt;br /&gt;
To tell Postfix that this &#039;&#039;vmail&#039;&#039; user is someone special, we run&lt;br /&gt;
 postconf -e virtual_uid_maps=static:120&lt;br /&gt;
 postconf -e virtual_gid_maps=static:120&lt;br /&gt;
That makes postfix understand that all mail for the virtual mail domains must be written to disk with these specified user and group ID&#039;s.&lt;br /&gt;
&lt;br /&gt;
==MySQL configuration==&lt;br /&gt;
&lt;br /&gt;
===Database preparation===&lt;br /&gt;
We will use the MySQL database to record data on our mail system, and then give our Postfix access to this database so that it can read its configuration from there. For starters, we&#039;ll create a MySQL database named &amp;quot;vmail&amp;quot;, and a MySQL user named &amp;quot;vmail_admin&amp;quot; that can read all necessary data from that &amp;quot;vmail&amp;quot; database. Then, we create the necessary tables, and a view that links these tables. We do this with the MySQL client &#039;&#039;mysql&#039;&#039;. However, we&#039;re quite lazy, so we don&#039;t create this database by hand (that&#039;s error-prone), but by use of a script [[create.vmail.sql]]. To this end, feed the [[create.vmail.sql]] script into the &#039;&#039;mysql&#039;&#039; client like this:&lt;br /&gt;
 mysql -u root -p &amp;lt; create.vmail.sql&lt;br /&gt;
(This of course assumes you have &#039;&#039;create.vmail.sql&#039;&#039; in your current working directory; if not you can include the path to the file.) Simply give the MySQL root user password, and the script creates the database, the user, the necessary tables, and the view.&amp;lt;br&amp;gt;&lt;br /&gt;
A note of caution: it is never a good idea to just run scripts without a proper understanding of what it does. Especially with MySQL, it will be advantageous if you understand the SQL commands. Open the script in a text editor, open the [http://dev.mysql.com/doc/refman/5.0/en/ MySQL command reference], and trace back what the script does exactly.&lt;br /&gt;
&lt;br /&gt;
===Inserting data===&lt;br /&gt;
Next up, we fill the database with the first sets of values (either test data or the first of our production data). We&#039;ll start off with the virtual domains that we&#039;re hosting, by running the mysql client and feeding it information like this:&lt;br /&gt;
 mysql -u root -p vmail&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (id, vdomain) VALUES (1, &#039;saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;wiki.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;shop.saruman.biz&#039;);&lt;br /&gt;
This has the effect of creating three entries. You can check that everything worked as planned by executing&lt;br /&gt;
 mysql&amp;gt; select * from virtual_domains;&lt;br /&gt;
Note: only the first entry needs an &#039;&#039;id&#039;&#039; value, because in MySQL we&#039;ve defined that field as AUTO_INCREMENT. After creating your first virtual domain in the table, you never have to use a statement like the first INSERT again, only statements like the other two.&lt;br /&gt;
&lt;br /&gt;
Now the MySQL database has the information needed by Postfix to recognise that you have three virtual mail domains (namely the three domains in the VALUES section) for which it hosts virtual mailboxes. Postfix cannot read this information yet, but that&#039;ll be taken care of in the next section.&lt;br /&gt;
&lt;br /&gt;
Whle still within the mysql client, we can now create users:&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (id, domain_id, user, passwd) VALUES (1, 1, &#039;jan&#039;, MD5(&#039;JanSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (1, &#039;mike&#039;, MD5(&#039;MikeSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (3, &#039;shopkeeper&#039;, MD5(&#039;ShopSecret&#039;));&lt;br /&gt;
This has the effect of creating three users &amp;quot;jan&amp;quot; (in domain saruman.biz), &amp;quot;mike&amp;quot; (in domain saruman.biz) and &amp;quot;shopkeeper&amp;quot; (in domain shop.saruman.biz). Again, the &#039;&#039;id&#039;&#039; value is only ever needed in the first statement, because from now on every user addition will auto-increment &#039;&#039;id&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The passwords shown are encrypted with MD5, and put in the &#039;&#039;passwd&#039;&#039; field. Later on, the users will be able to access their mailboxes using this password; we won&#039;t tell Postfix anything about them, because it doesn&#039;t need the passwords. You can check the content of the &#039;&#039;virtual_users&#039;&#039; table with the right &amp;quot;select&amp;quot; statement, and you can now also see that the view &#039;&#039;view-users&#039;&#039; works:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_users;&lt;br /&gt;
 mysql&amp;gt; select * from view_users;&lt;br /&gt;
&lt;br /&gt;
Should you need to update a user&#039;s password from the command line, you can use the following command, provided you&#039;ve looked up that user&#039;s &#039;&#039;id&#039;&#039; :&lt;br /&gt;
 UPDATE virtual_users set passwd = &#039;MD5(&#039;&amp;lt;password&amp;gt;&#039;)&#039; WHERE id = &#039;&amp;lt;id&amp;gt;&#039;;&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;re going to add some aliases, which are alternative e-mail addresses for the users; their primary e-mail address can already be seen in the &#039;&#039;view_users&#039;&#039; view, but perhaps you also want mail to &amp;quot;webmaster@shop.saruman.biz&amp;quot; to arrive at one or more mailboxes, e.g. in the mailbox for user &amp;quot;shopkeeper&amp;quot; (within domain &amp;quot;shop.saruman.biz&amp;quot;) and this guy&#039;s home address (&amp;quot;j.doe@example.com&amp;quot;). Furthermore, we&#039;ll define catchall-addresses for all domains, that&#039;ll send all mail for which no mailbox can be found to the mailbox of user Mike (for the first two domains) and Webmaster (for shop.saruman.biz; Webmaster himself is an alias yet again, that points to shopkeeper@shop.saruman.biz). To create the catchall, leave out a value for the source address. This creates the empty value for source that will be expanded (using source@domain) to &amp;quot;@domain&amp;quot;.&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (id, domain_id, source, destination)&lt;br /&gt;
        VALUES (1, 2, &#039;webmaster&#039;, &#039;shopkeeper@shop.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, source, destination)&lt;br /&gt;
        VALUES (2, &#039;webmaster&#039;, &#039;j.doe@example.com&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (1, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (2, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (3, &#039;webmaster@saruman.biz&#039;);&lt;br /&gt;
 &lt;br /&gt;
Again, we don&#039;t need to add the &#039;&#039;id&#039;&#039; value any more after the first ever insertion into this table.&lt;br /&gt;
&lt;br /&gt;
We can check the result by running a select statement against the &#039;&#039;virtual_aliases&#039;&#039; table and &#039;&#039;view_aliases&#039;&#039; view:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_aliases;&lt;br /&gt;
 mysql&amp;gt; select * from view_aliases;&lt;br /&gt;
&lt;br /&gt;
== Postfix configuration for MySQL lookups==&lt;br /&gt;
Next, we&#039;re going to tell Postfix to use the &#039;&#039;vmail&#039;&#039; database, and also how to read the database (Postfix never writes the MySQL database). To this end, we&#039;re going to create three configuration files in directory &#039;&#039;/etc/postfix&#039;&#039;. We&#039;ll start off with one configuration file, with which Postfix can determine if a domain name is among the domain(s) that it&#039;s actually hosting mailboxes for. Then we&#039;ll create the config file that checks the table that contains all the users that have a virtual mailbox, and finally we create the lookup for the table with all the aliases.&lt;br /&gt;
&lt;br /&gt;
===Virtual mail domains lookup===&lt;br /&gt;
&lt;br /&gt;
Create file &#039;&#039;/etc/postfix/mysql-virtual-domains.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM virtual_domains WHERE vdomain=&#039;%s&#039;&lt;br /&gt;
Next, we tell postfix to check this configuration file when it needs to check &amp;quot;virtual_mailbox_domains&amp;quot;:&lt;br /&gt;
 postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
Use of this configuration file in postfix has the effect of returning &amp;quot;yes&amp;quot; when checking our database for the domain part of an email address. Naturally, this configuration file has to be fitted with the actual &#039;&#039;vmail_admin&#039;&#039; password rather than our example &amp;quot;SuperSecret&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Virtual mail user lookup===&lt;br /&gt;
Create the file &#039;&#039;/etc/postfix/mysql-virtual-mailbox-maps.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
Next, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_mailbox_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
The lookup of virtual mailboxes should work with the data we&#039;ve put into the database previously. i.e.&lt;br /&gt;
 postmap -q jan@saruman.biz mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
should return a &#039;&#039;&#039;1&#039;&#039;&#039; to acknowledge that &amp;quot;jan@saruman.biz&amp;quot; is indeed a virtual mailbox in our Postfix configuration.&lt;br /&gt;
&lt;br /&gt;
=== Virtual alias lookup===&lt;br /&gt;
Create another cf file at &#039;&#039;/etc/postfix/mysql-virtual-alias-maps.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT destination FROM view_aliases WHERE email=&#039;%s&#039;&lt;br /&gt;
And create yet another cf file at &#039;&#039;/etc/postfix/mysql-email2email.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT email FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
&lt;br /&gt;
Again, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_alias_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf&lt;br /&gt;
The lookup of virtual aliases should now work as designed:&lt;br /&gt;
 postmap -q shopkeeper@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
 postmap -q webmaster@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
If you&#039;ve put in the data from the previous section, then both commands should return the same result: &#039;&#039;shopkeeper@saruman.biz&#039;&#039;. This shows that Postfix will deliver  mail to shopkeeper or to webmaster to the mailbox of shopkeeper.&lt;br /&gt;
&lt;br /&gt;
===Finishing up configuration files===&lt;br /&gt;
When everything works as planned, then we secure the configuration files against prying eyes. Remember, the configuration files contain the user/password combination which which to access the &#039;&#039;vmail&#039;&#039; SQL database. The &#039;&#039;vmail_admin&#039;&#039; user has only read rights, and passwords in there are encrypted, but nevertheless, this is information we need to protect. Thus:&lt;br /&gt;
 chown root:postfix /etc/postfix/mysql-*.cf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/postfix/mysql-*.cf&lt;br /&gt;
This protects all four configuration files since only root can write them, members of group &#039;&#039;postfix&#039;&#039; can read them, and the rest of the world cannot access them at all.&lt;br /&gt;
&lt;br /&gt;
==Configuring mail delivery through Dovecot LDA==&lt;br /&gt;
E-mails get delivered to the virtual mailboxes by means of a Mail Delivery Agent (MDA). With Postfix, the standard MDA for delivery to virtual mailboxes is called &#039;&#039;virtual&#039;&#039;, but we&#039;re not going to use that; we&#039;re going to use &#039;&#039;[http://wiki.dovecot.org/LDA Dovecot LDA]&#039;&#039;, which is a program called &#039;&#039;deliver&#039;&#039;. By the way, the abbreviation LDA stands for Local Delivery Agent, which of course means more or less the same as MDA.&lt;br /&gt;
===Enabling the Dovecot daemon===&lt;br /&gt;
To make Postfix use Dovecot LDA, we add the following line to &#039;&#039;/etc/postfix/master.cf&#039;&#039;:&lt;br /&gt;
 dovecot   unix  -       n       n       -       -       pipe&lt;br /&gt;
     flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}&lt;br /&gt;
This declares the service &amp;quot;dovecot&amp;quot; to mean using the program &#039;&#039;/usr/lib/dovecot/deliver&#039;&#039; with the right parameters. If we now let Postfix reload its files, it&#039;ll learn about this new service. Subsequently we can instruct Postfix to start using it, by declaring service &amp;quot;dovecot&amp;quot; to be the virtual transport of choice, and specifying one Dovecot-specific variable:&lt;br /&gt;
 postfix reload&lt;br /&gt;
 postconf -e virtual_transport=dovecot&lt;br /&gt;
 postconf -e dovecot_destination_recipient_limit=1&lt;br /&gt;
===Dovecot default configuration===&lt;br /&gt;
Now to configure Dovecot itself: open &#039;&#039;/etc/dovecot/dovecot.conf&#039;&#039; with your favourite editor [[vim]]; first make sure the &#039;&#039;protocols =&#039;&#039; line reads&lt;br /&gt;
 protocols = imap imaps pop3 pop3s&lt;br /&gt;
(which it should by default). The second setting is quite crucial. By default, the location of the mail directories is found automatically by Dovecot, but here that won&#039;t work. Find the line that reads &#039;&#039;#mail_location =&#039;&#039;, and change it to&lt;br /&gt;
 mail_location = maildir:/data/vmail/%d/%n/Maildir&lt;br /&gt;
This will look for mail in directory &#039;&#039;/data/vmail/&#039;&#039;&#039;DOMAIN&#039;&#039;&#039;/&#039;&#039;&#039;USER&#039;&#039;&#039;/Maildir&#039;&#039;, and expect this directory to be in &amp;quot;maildir&amp;quot; format.&lt;br /&gt;
Next look for a section called &amp;quot;auth default&amp;quot;. First define the allowed authentication mechanisms:&lt;br /&gt;
 mechanisms = plain login&lt;br /&gt;
Then inside that same section you need to uncomment:&lt;br /&gt;
 passdb sql {&lt;br /&gt;
     args = /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 }&lt;br /&gt;
which tells Dovecot that the passwords are stored in an SQL database (it&#039;s obvious that we&#039;ll now have to create this conf-file) and:&lt;br /&gt;
 userdb static {&lt;br /&gt;
     args = uid=120 gid=120 home=/data/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
to tell Dovecot where the mailboxes are located. This is similar to the &#039;&#039;mail_location&#039;&#039; setting. Next task: comment out the section &#039;&#039;passdb pam&#039;&#039;, so that Dovecot doesn&#039;t accidentally try to service local users as well.&lt;br /&gt;
&lt;br /&gt;
Next up: tell Dovecot to handle IMAP the same as previous versions of this virtual mailserver have - this can prove to be quite tricky if you already have mailboxes full of mail, put there by e.g. Courier-IMAP. What works for us, is&lt;br /&gt;
 namespace private {&lt;br /&gt;
     separator = .&lt;br /&gt;
     prefix = &lt;br /&gt;
     inbox = yes&lt;br /&gt;
 }&lt;br /&gt;
However, your mileage may vary.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to comment out the &#039;&#039;passdb pam&#039;&#039; sections, since we&#039;re not hosting mail for local users.&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;ll edit the section &#039;&#039;socket listen&#039;&#039; so that Dovecot can access the user database (master section), and our Postfix mailserver can access Dovecot (client section):&lt;br /&gt;
 socket listen {&lt;br /&gt;
   master {&lt;br /&gt;
     path = /var/run/dovecot/auth-master&lt;br /&gt;
     mode = 0600&lt;br /&gt;
     user = vmail&lt;br /&gt;
   }&lt;br /&gt;
   client {&lt;br /&gt;
     path = /var/spool/postfix/private/auth&lt;br /&gt;
     mode = 0660&lt;br /&gt;
     user = postfix&lt;br /&gt;
     group = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Finally, the protocol section, where we specify log files, an address to put in mails when we send out nondelivery reports, and a place to store scripts:&lt;br /&gt;
 protocol lda {&lt;br /&gt;
     log_path = /var/log/appslog/mail/dovecot-deliver.log&lt;br /&gt;
     auth_socket_path = /var/run/dovecot/auth-master&lt;br /&gt;
     postmaster_address = postmaster@saruman.biz&lt;br /&gt;
     mail_plugins = cmusieve&lt;br /&gt;
     global_script_path = /data/vmail/globalsieverc&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You could change the log path to &amp;quot;log_path =&amp;quot; With a empty logpath syslog will log the events. &lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve finished the Dovecot configuration file, we need to create a fitting MySQL configuration file for Dovecot. The file is &#039;&#039;/etc/dovecot/dovecot-sql.conf&#039;&#039;, and its contents are&lt;br /&gt;
 driver = mysql&lt;br /&gt;
 connect = host=127.0.0.1 dbname=vmail user=vmail_admin password=SuperSecret&lt;br /&gt;
 default_pass_scheme = PLAIN-MD5&lt;br /&gt;
 password_query = SELECT email as user, passwd as password FROM view_users WHERE email=&#039;%u&#039;;&lt;br /&gt;
When you&#039;ve created this file (as root), change the attributes of &#039;&#039;dovecot-sql.conf&#039;&#039; and &#039;&#039;dovecot.conf&#039;&#039;, and then restart Dovecot to start using the new configuration. Note: &#039;&#039;dovecot.conf&#039;&#039; needs to be read by Postfix, hence the group ownership for the file.&lt;br /&gt;
 chmod u=rw,g=,o= /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 chgrp vmail /etc/dovecot/dovecot.conf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/dovecot/dovecot.conf&lt;br /&gt;
 /etc/init.d/dovecot restart&lt;br /&gt;
&lt;br /&gt;
To get some more logging in the case something goes wrong. Uncomment the folling and change to yes.&lt;br /&gt;
 auth_verbose = yes&lt;br /&gt;
 auth_debug = yes&lt;br /&gt;
 auth_debug_passwords = yes&lt;br /&gt;
&lt;br /&gt;
===Dovecot SSL configuration===&lt;br /&gt;
Out of the (Debian) box, Dovecot is SSL-enabled. We&#039;ll now replace the generic SSL-certificate, generated for the host by the Dovecot installation script, by our own certificate. To ths end, we first [[Creating_digital_certificates_with_our_root_certificate | generate an appropriate certificate]], e.g. an SSL wildcard certificate: &amp;quot;*.saruman.biz&amp;quot;. This results in a public and a private certificate, both of which must be placed somewhere where Dovecot expects them and can read them.&lt;br /&gt;
&lt;br /&gt;
By default, Dovecot expects the following locations/filenames/owner/attributes:&lt;br /&gt;
 /etc/ssl/certs/dovecot.pem    -rw-r--r--  root:dovecot  4624 bytes&lt;br /&gt;
 /etc/ssl/private/dovecot.pem  -rw-------  root:dovecot  1743 bytes&lt;br /&gt;
If we may make a suggestion: rename the generated certificates in both locations to dovecot.pem.bak, place your generated certificates in their place, and set the owner/permissions like displayed here.&lt;br /&gt;
&lt;br /&gt;
However, if you&#039;ve generated your own keys, you might have used a passphrase on the private key. You&#039;ll have to tell dovecot about it in its configuration file /etc/dovecot/dovecot.conf. To this end, edit the corresponding section by uncommenting the &amp;quot;ssl_&amp;quot; lines, and using your private key password (e.g. &amp;quot;zM7Ertq12&amp;quot;) in the appropriate line:&lt;br /&gt;
 ssl_cert_file = /etc/ssl/certs/dovecot.pem&lt;br /&gt;
 ssl_key_file = /etc/ssl/private/dovecot.pem&lt;br /&gt;
 &lt;br /&gt;
 # If key file is password protected, give the password here. Alternatively&lt;br /&gt;
 # give it when starting dovecot with -p parameter.&lt;br /&gt;
 ssl_key_password = zM7Ertq12&lt;br /&gt;
Naturally you are free to place the keys in a different location, and/or use a different name...&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
&lt;br /&gt;
This is a good moment to test your configuration, if you haven&#039;t been able to test your work inbetween. If everything works as expected, you can add bells and whistles to your configuration.&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;smtpd&#039;&#039; TLS encryption===&lt;br /&gt;
The first addition we&#039;d like to present covers the way Postfix handles incoming connections. Since authentication works, we can have Postfix distrust every (unauthenticated) connection:&lt;br /&gt;
 postconf -e mynetworks=&lt;br /&gt;
Furthermore, since a default SSL certificate is installed by the Debian Postfix installation routine, we can encrypt all our connections using TLS; we enforce this using&lt;br /&gt;
 postconf -e smtpd_use_tls=yes&lt;br /&gt;
 postconf -e smtpd_tls_auth_only=yes&lt;br /&gt;
Of course, you need to adjust the settings of your IMAP client so that it properly uses TLS and properly authenticates itself.&lt;br /&gt;
&lt;br /&gt;
If TLS works, you&#039;ll probably want to change the certificate as you have for Dovecot in the previous section. This is again pretty easy. If you haven&#039;t yet, now is the time to [[Creating_digital_certificates_with_our_root_certificate | creating that custom SSL certificate]] for our mail server - but you have to make sure that you DON&#039;T use a password on the private key. Unlike Dovecot, Postfix cannot be told the password to the private key somewhere.&lt;br /&gt;
&lt;br /&gt;
For starters, look at the TLS-section of your &#039;&#039;main.cf&#039;&#039; that you currently have. Chances are a big chunk of it looks like this:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Now all you need to do is replace the name of the snakeoil-keys with those of appropriate ssl-certificates, the private key of which needs to be NOT passphrase-protected. For this you could copy the Dovecot certificates, if you strip that passphrase in the manner described in the [[Creating_digital_certificates_with_our_root_certificate#Creating_an_SSL_certificate | SSL certificate section]]. The &#039;&#039;main.cf&#039;&#039; then would become:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/postfix.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/postfix.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Restart Postfix, and presto.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other additions ===&lt;br /&gt;
If everything &#039;&#039;still&#039;&#039; works after these changes, then congratulations, you now have a powerful, flexible and pretty secure mail setup. Of course, there are always points for improvements. We&#039;ll cover these in separate pages. One page that we want to direct you to now, is&lt;br /&gt;
* [[Antispam measures]] for our Postfix mailserver&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenLDAP&amp;diff=3082</id>
		<title>OpenLDAP</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenLDAP&amp;diff=3082"/>
		<updated>2016-02-21T21:44:27Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Post-install reconfiguration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note: if you need information on the OpenLDAP version from Debian 5.0, see this page: [[OpenLDAP 2.4.11]]&lt;br /&gt;
&lt;br /&gt;
== OpenLDAP installation==&lt;br /&gt;
Note: we&#039;re going to install OpenLDAP on our server as [http://www.openldap.org/doc/admin24/config.html#Local%20Directory%20Service the local directory service], without replication, referrals or other advanced features. Under Debian Squeeze, this is OpenLDAP 2.4.23.&lt;br /&gt;
&lt;br /&gt;
===Standard installation===&lt;br /&gt;
Installing OpenLDAP on your Debian server is ridiculously simple. Just make sure your server is up-to-date (&#039;&#039;sudo apt-get update&#039;&#039; followed by &#039;&#039;sudo apt-get upgrade&#039;&#039;), and then install the two main components for your OpenLDAP server. First off: the LDAP client and utilities&lt;br /&gt;
 sudo apt-get install ldap-utils&lt;br /&gt;
This will result in the installation of as much as 8 different packages (&#039;&#039;ldap-utils&#039;&#039;, &#039;&#039;libgcrypt11&#039;&#039;, &#039;&#039;libgnutls26&#039;&#039;, &#039;&#039;libgpg-error0&#039;&#039;, &#039;&#039;libldap-2.4-2&#039;&#039;, &#039;&#039;libsasl2-2&#039;&#039;, &#039;&#039;libsasl2-modules&#039;&#039;, and &#039;&#039;libtasn1-3&#039;&#039;). Next the main component of an LDAP server installation, the stand-alone LDAP daemon &amp;quot;slapd&amp;quot;&lt;br /&gt;
 sudo apt-get install slapd&lt;br /&gt;
This may also install up to 8 packages (&#039;&#039;slapd&#039;&#039;, &#039;&#039;libltdl7&#039;&#039;, &#039;&#039;libperl5.10&#039;&#039;, &#039;&#039;libslp1&#039;&#039;, &#039;&#039;odbcinst&#039;&#039;, &#039;&#039;odbcinst1debian2&#039;&#039;, &#039;&#039;psmisc&#039;&#039; and &#039;&#039;unixodbc&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The Debian configuration script will ask you for only one single thing: an administrator password. As always: generate a strong password! After you&#039;ve provided the password, the LDAP database is created with the administrator name &amp;quot;admin&amp;quot; and as a base directory, something based on your DNS name. Suppose your internal domain is &amp;quot;amber.lan&amp;quot;, then the script will generate &#039;&#039;suffix &amp;quot;dc=amber,dc=lan&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;Should you see a third, empty, domain component (&#039;&#039;dc=&#039;&#039;) then this is caused by a trailing dot in your particular DNS name: the DNS root. You might have specified your domain as &amp;quot;amber.lan.&amp;quot;. You &#039;&#039;should&#039;&#039; change your domain name to a name without the DNS root, and you &#039;&#039;must&#039;&#039; regenerate your LDAP directory.&amp;lt;/ref&amp;gt;.&lt;br /&gt;
The above method of configuring yields you an LDAP database with only two objects in it. Suppose your DNS name is &amp;quot;easton2.amber.lan&amp;quot;, then the two objects are:&lt;br /&gt;
* a single Organization (o=&amp;quot;amber.lan&amp;quot;) with Distinguished Name dn=&amp;quot;dc=amber,dc=lan&amp;quot;&lt;br /&gt;
* a single administrator with Common Name cn=&amp;quot;admin&amp;quot;, and dn=&amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&lt;br /&gt;
Note, however, that there&#039;s &#039;&#039;also&#039;&#039; a second LDAP database, &amp;quot;cn=config&amp;quot;, which on your server is located under &#039;&#039;/etc/ldap/slapd.d&#039;&#039;. We&#039;ll cover what&#039;s in it further on.&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing the installation===&lt;br /&gt;
After installation of the package, it should automatically have been started, and should now be operational. This can be checked with a utility like &#039;&#039;nmap&#039;&#039;:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;nmap -p 389 localhost&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Starting Nmap 5.00 ( &amp;lt;nowiki&amp;gt;http://nmap.org&amp;lt;/nowiki&amp;gt; ) at 2011-04-13 21:19 CEST&lt;br /&gt;
 Interesting ports on localhost (127.0.0.1):&lt;br /&gt;
 PORT    STATE SERVICE&lt;br /&gt;
 389/tcp open  ldap  &lt;br /&gt;
 &lt;br /&gt;
 Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds&lt;br /&gt;
 root@easton2:~#&#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Another way to test if the LDAP server is functional, is by querying it with the &#039;&#039;ldapsearch&#039;&#039; utility, part of the package &#039;&#039;ldap-utils&#039;&#039;. Let&#039;s see if we can find the naming context of the LDAP server:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -x -b &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt; -s base &#039;(objectclass=*)&#039; namingContexts&#039;&#039;&#039;&lt;br /&gt;
 # extended LDIF&lt;br /&gt;
 #&lt;br /&gt;
 # LDAPv3&lt;br /&gt;
 # base &amp;lt;&amp;gt; with scope baseObject&lt;br /&gt;
 # filter: (objectclass=*)&lt;br /&gt;
 # requesting: namingContexts&lt;br /&gt;
 #&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 dn:&lt;br /&gt;
 namingContexts: dc=amber,dc=lan&lt;br /&gt;
 &lt;br /&gt;
 # search result&lt;br /&gt;
 search: 2&lt;br /&gt;
 result: 0 Success&lt;br /&gt;
 &lt;br /&gt;
 # numResponses: 2&lt;br /&gt;
 # numEntries: 1&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
With this command, we do a search using&lt;br /&gt;
* basic authentication (instead of one encrypted with SASL),&lt;br /&gt;
* searching within the LDAP tree from base &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt; (meaning the absolute root of the tree),&lt;br /&gt;
* looking for base object only (instead of a one-level search, a subtree search, or a children-search),&lt;br /&gt;
* filtering for objects of any class,&lt;br /&gt;
* asking for the naming context of the result.&lt;br /&gt;
The output shows that the server responds; two objects have been considered, but none match the filter (that the object should have an objectClass).&lt;br /&gt;
&lt;br /&gt;
Let&#039;s now do the same but with authentication, to see if we can bind to the LDAP server. We&#039;ll first use an incorrect password, then the correct one:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -W -D &amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 Enter LDAP Password:&lt;br /&gt;
 ldap_bind: Invalid credentials (49)&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -W -D &amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 Enter LDAP Password:&lt;br /&gt;
 # extended LDIF&lt;br /&gt;
 #&lt;br /&gt;
 # LDAPv3&lt;br /&gt;
 # base &amp;lt;&amp;gt; (default) with scope subtree&lt;br /&gt;
 # filter: (objectclass=*)&lt;br /&gt;
 # requesting: ALL&lt;br /&gt;
 #&lt;br /&gt;
 &lt;br /&gt;
 # search result&lt;br /&gt;
 search: 2&lt;br /&gt;
 result: 32 No such object&lt;br /&gt;
 &lt;br /&gt;
 # numResponses: 1&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Finally, you could simply install and run a graphical management tool for LDAP servers, like [http://directory.apache.org/studio/ Apache Directory Studio]. Note however that if this check fails, then this could also mean problems with firewalls, network connections et cetera.&lt;br /&gt;
&lt;br /&gt;
===Post-install reconfiguration===&lt;br /&gt;
Since the default configuration with the server&#039;s DNS domain as LDAP base might not always be the most convenient configuration, you could run the configuration again using &#039;&#039;dpkg-reconfigure slapd&#039;&#039;. However, following this procedure is &#039;&#039;&#039;only&#039;&#039;&#039; necessary if you want to change any of the default installation values like the backend database type or DNS domain name; things like the organization name can be edited with other means, as will be shown later on.&lt;br /&gt;
&lt;br /&gt;
To be able to reconfigure the LDAP service, you can run the reconfiguration command &#039;&#039;sudo dpkg-reconfigure slapd&#039;&#039;. Contrary to some older versions of Debian, you do not need to manually stop the &#039;&#039;slapd&#039;&#039; daemon, and you don&#039;t need to manually remove the old configuration or database (in fact, if you do, then the &#039;&#039;slapd&#039;&#039; package will break, so you cannot easily remove it with APT tools). Interestingly enough, this reconfiguration asks you many &#039;&#039;more&#039;&#039; questions. The answers could look like this:&lt;br /&gt;
 omit OpenLDAP config:  no&lt;br /&gt;
 DNS domain name:       saruman.biz&lt;br /&gt;
 Organization name:     Saruman&lt;br /&gt;
 Administrator passwd:  wEt3udes&lt;br /&gt;
 Database backend:      MDB&lt;br /&gt;
 DB remove after purge: yes&lt;br /&gt;
 Move old DB:           yes&lt;br /&gt;
 Allow LDAPv2:          no&lt;br /&gt;
As you can see, the reconfiguration yields much more configuration options than plain installation - although really you&#039;ll probably answer most questions with their default values anyway. The above method of configuring yields you an LDAP database with only two objects in it:&lt;br /&gt;
* a single Organization (o=&amp;quot;Saruman&amp;quot;) with Distinguished Name dn=&amp;quot;dc=saruman,dc=biz&amp;quot;&lt;br /&gt;
* a single administrator with Common Name cn=&amp;quot;admin&amp;quot;, and dn=&amp;quot;cn=admin,dc=saruman,dc=biz&amp;quot;&lt;br /&gt;
Also note that the reconfiguration creates a backup of the &amp;quot;old&amp;quot; LDAP database in a directory with a name like &#039;&#039;/var/backups/unknown-2.4.40+dfsg-1+deb8u2.ldapdb&#039;&#039;; if you just reconfigured after installation, then you probably don&#039;t need this backup, so you can remove it.&lt;br /&gt;
&lt;br /&gt;
The database that your OpenLDAP server uses is a standard Berkeley DB (BDB/HDB) database or something similar. Now we most likely will require some other databases as well in our server setup, something modern like PostgreSQL or MySQL - so why don&#039;t we configure our OpenLDAP to use this same database as well? For the answer, see [http://www.openldap.org/doc/admin24/intro.html#LDAP%20vs%20RDBMS here] - in short, the LDAP tree structure does not lend itself very well to inclusion in a modern relational database. Thus, we advise to stick with one of the specialized databases provided with Debian/OpenLDAP. Now, for the database backend, we have the choice between the following flavours:&lt;br /&gt;
* the &#039;&#039;bdb&#039;&#039; backend used to be the recommended primary backend for a normal slapd database. It uses the Oracle Berkeley DB package, referred to as &#039;&#039;BDB&#039;&#039;, to store data. It makes extensive use of indexing and caching to speed data access.&lt;br /&gt;
* the &#039;&#039;hdb&#039;&#039; backend is a variant of the &#039;&#039;bdb&#039;&#039; backend that uses a hierarchical database layout which supports subtree renames. It is otherwise identical to the &#039;&#039;bdb&#039;&#039; behavior, and all the same configuration options apply.&lt;br /&gt;
* the &#039;&#039;mdb&#039;&#039; backend is a transactional backend built on OpenLDAP&#039;s [https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database Lightning Memory-Mapped Database] (LMDB).&lt;br /&gt;
In Debian 8.0 &amp;quot;Jessie&amp;quot; with OpenLDAP 2.4.40, MDB is the default backend.&lt;br /&gt;
&lt;br /&gt;
==OpenLDAP server configuration==&lt;br /&gt;
&amp;lt;small&amp;gt;(text from http://www.rjsystems.nl/en/2100-d6-openldap-provider.php)&amp;lt;/small&amp;gt; As of OpenLDAP 2.4.23-3, the &#039;&#039;slapd&#039;&#039; runtime configuration is fully LDAP-enabled. The default is to manage it using the standard LDAP operations with data in LDIF. The old &#039;&#039;slapd.conf&#039;&#039; format is still supported, but since that file must now be converted to the new &#039;&#039;slapd-config&#039;&#039; format to allow runtime changes to be saved, it seems likely that the developers will eventually phase it out. Therefore, we&#039;ll focus only on the new configuration method, the main advantage of which is that any changes made are immediately active, so it is no longer necessary to restart &#039;&#039;slapd&#039;&#039; after making configuration changes.&lt;br /&gt;
&lt;br /&gt;
The new configuration format uses a slapd backend database that is found in the &#039;&#039;/etc/ldap/slapd.d/&#039;&#039; directory. The configuration is stored as a special LDAP directory with a predefined schema and DIT, the root of which is called &#039;&#039;cn=config&#039;&#039;. If you go look there, you&#039;ll find that most parts of this LDAP directory consist of editable flat files.&lt;br /&gt;
&lt;br /&gt;
===Check the current LDAP configuration===&lt;br /&gt;
From the command line, there really are several ways to check the current LDAP configuration:&lt;br /&gt;
* from the server itself, you can use the trusty &#039;&#039;ldapsearch&#039;&#039; command, running under root: this&#039;ll authenticate with user ID 0. Filtering only for distinguished names:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn=module{0},cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={0}core,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={1}cosine,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={2}nis,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={3}inetorgperson,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcBackend={0}hdb,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={-1}frontend,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* to get an idea of what the &#039;&#039;cn=config&#039;&#039; database looks like &#039;&#039;within LDAP itself&#039;&#039;, you can run this command:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;slapcat -b cn=config&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 objectClass: olcGlobal&lt;br /&gt;
 cn: config&lt;br /&gt;
 olcArgsFile: /var/run/slapd/slapd.args&lt;br /&gt;
 olcLogLevel: none&lt;br /&gt;
 olcPidFile: /var/run/slapd/slapd.pid&lt;br /&gt;
 olcToolThreads: 1&lt;br /&gt;
 &#039;&#039;&#039;&#039;&#039;(more LDIF texts)&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
 entryUUID: f2a8f568-fa40-102f-8b9d-5d4cbccf32a9&lt;br /&gt;
 creatorsName: cn=admin,cn=config&lt;br /&gt;
 createTimestamp: 20110413174103Z&lt;br /&gt;
 entryCSN: 20110413174103.641065Z#000000#000#000000&lt;br /&gt;
 modifiersName: cn=admin,cn=config&lt;br /&gt;
 modifyTimestamp: 20110413174103Z&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
: As you can see, this generates a pretty large LDIF dump of the contents of the &#039;&#039;cn=config&#039;&#039; directory. Much of it consists of schema information. The LDAP configuration directives are attributes of the directory entries (objects) and most them start with the prefix &amp;quot;olc&amp;quot; (&#039;&#039;&#039;O&#039;&#039;&#039;pen&#039;&#039;&#039;L&#039;&#039;&#039;DAP &#039;&#039;&#039;C&#039;&#039;&#039;onfiguration). Also, some of the objects have names with numbers between curly brackets. This is to compensate for the fact that LDAP databases do not store their contents in any particular order; they are inherently unordered. The numbers constitute a numeric index to ensure a consistent order in the configuration database and thereby preserve all ordering dependencies. The index numbers, however, are generated automatically in the order they are created and usually do not have to be provided.&lt;br /&gt;
* you can see the configuration by browsing through all the plain-text flat files in &#039;&#039;/etc/ldap/slapd.d/&#039;&#039; and its subdirectories.&lt;br /&gt;
Note that by default there is no way to do this remotely. If you&#039;d like to browse this configuration using a GUI tool like [http://directory.apache.org/studio/ apache directory studio], don&#039;t bother. Debian sets the &#039;&#039;cn=config&#039;&#039; part of the database with a root user of &#039;&#039;cn=admin,cn=config&#039;&#039;, but without a password, so you cannot bind to the &#039;&#039;cn=config&#039;&#039; database as anything else than the local root user. Thus you cannot access the &#039;&#039;cn=config&#039;&#039; database by GUI.&lt;br /&gt;
&lt;br /&gt;
===Adding or modifying the cn=config admin password===&lt;br /&gt;
To add a password to the config RootDN, we first must generate one; for this we can use the &#039;&#039;slappasswd&#039;&#039; command. By default it&#039;ll create an SSHA password, but by specifying MD5 as hash (using &#039;&#039; -h {MD5}&#039;&#039;) it will create an MD5 encrypted password. The command interactively asks you for the password, and won&#039;t show you what you&#039;ve typed, so be precise:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;slappasswd -h {MD5}&#039;&#039;&#039;&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-enter new password:&lt;br /&gt;
 {MD5}d5axCh6gYGjhfK4PGs09us==&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Now we determine the DN (Distinguished Name) for the database that contains the RootDN password. We&#039;ll also check if there isn&#039;t a password in place already. To do this we used the following LDAP search command.&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b  cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 olcRootDN: cn=admin,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the olcDatabase line, as it&#039;s the result we were looking for; it&#039;ll be needed for the &#039;&#039;ldapmodify&#039;&#039; command. Furthermore, note the absence of an olcRootPW entry; this is the starting point for a Debian OpenLDAP server.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can stick in a new password. If no password is present, you can use this interactive procedure:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={0}config,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;add: olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcRootPW: {MD5}d5axCh6gYGjhfK4PGs09us==&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the following points:&lt;br /&gt;
* we use the olcDatabase location as found with the previous &#039;&#039;ldapsearch&#039;&#039; command;&lt;br /&gt;
* we input the MD5 password that we&#039;ve generated previously;&lt;br /&gt;
* as soon as you put in an empty line, the entry gets added;&lt;br /&gt;
* you have to use CTRL-D to end this interactive mode;&lt;br /&gt;
* if a password was already in place, we could still use the above, but we&#039;d interactively feed the second line as &#039;&#039;&#039;replace: olcRootPW&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
We could also put the password in an ldif file, and feed that to the server. To this end, we&#039;d create an ldif file with the following content:&lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 changetype: modify&lt;br /&gt;
 add: olcRootPW&lt;br /&gt;
 olcRootPW: {MD5}d5axCh6gYGjhfK4PGs09us==&lt;br /&gt;
If this file is called &#039;&#039;addpassword.ldif&#039;&#039; and is created in &#039;&#039;/tmp&#039;&#039;, then the addition can be executed using&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/addpassword.ldif&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Adding or modifying (configuration) information==&lt;br /&gt;
The simple way of changing anything in the database goes like this:&lt;br /&gt;
===Method 1: interactive CLI tool===&lt;br /&gt;
As an example, let&#039;s add an index to the configuration. We&#039;ll start by seeing which indices already exist, then interactively add two indices. Finally, we check that the indices are there:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}hdb olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 olcDbIndex: objectClass eq&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={1}hdb,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;add: olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcDbIndex: cn eq&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcDbIndex: uid eq&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={1}hdb,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}hdb olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 olcDbIndex: objectClass eq&lt;br /&gt;
 olcDbIndex: cn eq&lt;br /&gt;
 olcDbIndex: uid eq&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
(And ofcourse we press ctrl-D to end interactive mode).&amp;lt;br&amp;gt;Note: we can /modify multiple attributes in one stanza, but we can also add multiple objects/attributes in one &#039;&#039;ldapmodify&#039;&#039; session:&lt;br /&gt;
* If you input an empty line, you can start another &#039;&#039;dn:&#039;&#039; line, and perform another action;&lt;br /&gt;
* If you input a minus sign by itself on a line, then OpenLDAP will assume you&#039;ll be performing another action in/on the same object.&lt;br /&gt;
&lt;br /&gt;
Modifying works almost the same; we only need keyword &#039;&#039;replace&#039;&#039; instead of &#039;&#039;add&#039;&#039;:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config -s base olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 olcLogLevel: none&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;changetype: modify&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;replace: olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcLogLevel: stats&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config -s base olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 olcLogLevel: stats&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the &#039;&#039;-s base&#039;&#039; option that limits the search for the &#039;&#039;olcLogLevel&#039;&#039; attribute to the &#039;&#039;cn=config&#039;&#039; container.&lt;br /&gt;
&lt;br /&gt;
Deleting information from an LDAP tree rarely ever happens, because once an attribute is used for anything, you aren&#039;t allowed to delete it, only modify it. However, if you want to delete anything, you can use the changetype &amp;quot;modify&amp;quot; with action &amp;quot;delete&amp;quot;:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={0}config,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;changetype: modify&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;delete: olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Method 2: use an ldif file===&lt;br /&gt;
===Method 3: use an LDAP browser===&lt;br /&gt;
With this method, you just use your LDAP browser for the addition or modification, according to its specific usage instructions. In the back, the tool will communicate with the LDAP server as you would in the previous methods. Note however, that this method relies on a bind account in the configuration database, which is a serious security risk.&lt;br /&gt;
&lt;br /&gt;
==Adding schemas==&lt;br /&gt;
A major task in LDAP maintenance is the addition of LDAP schemas. By default, only 4 schemas will be present in your LDAP server: &#039;&#039;core&#039;&#039;, &#039;&#039;cosine&#039;&#039;, &#039;&#039;nis&#039;&#039; and &#039;&#039;inetorgperson&#039;&#039;. Any other schema, -- say, for Samba -- would need to be added.&lt;br /&gt;
===Checking existing schemas===&lt;br /&gt;
Let&#039;s first check which schemas are already installed. Let&#039;s try two different methods, and see what they&#039;ll show out of the box:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=schema,cn=config &amp;quot;(objectClass=olcSchemaConfig)&amp;quot; dn&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={0}core,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={1}cosine,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={2}nis,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={3}inetorgperson,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ls -l /etc/ldap/slapd.d/cn=config/cn=schema&#039;&#039;&#039;&lt;br /&gt;
 total 40&lt;br /&gt;
 -rw------- 1 openldap openldap 15474 Jun 13 17:39 cn={0}core.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap 11308 Jun 13 17:39 cn={1}cosine.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap  6438 Jun 13 17:39 cn={2}nis.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap  2802 Jun 13 17:39 cn={3}inetorgperson.ldif&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
===Creating a suitable LDIF file for the schema===&lt;br /&gt;
To add a schema, you need a schema in LDIF format, which you can then add to the LDAP database using the &#039;&#039;ldapadd&#039;&#039; command.&lt;br /&gt;
Suppose you have a schema file &#039;&#039;samba.schema&#039;&#039; which you&#039;ve copied to the &#039;&#039;/etc/ldap/schema&#039;&#039; directory. You&#039;d first have to convert this to a suitable LDIF file. This can be done using &#039;&#039;slaptest&#039;&#039;, however &#039;&#039;slaptest&#039;&#039; requires access to the other schemas that your new schema is building on. So we now do this:&lt;br /&gt;
* We create a file &#039;&#039;schema_convert.conf&#039;&#039; with the content shown below. Note that we&#039;re including the schema files of all the schemas that are already in our LDAP server. Furthermore, because we may need it again with the next schema addition, it makes sense to save this file under &#039;&#039;/etc/ldap/schema&#039;&#039;:&lt;br /&gt;
 include /etc/ldap/schema/core.schema&lt;br /&gt;
 include /etc/ldap/schema/cosine.schema&lt;br /&gt;
 include /etc/ldap/schema/nis.schema&lt;br /&gt;
 include /etc/ldap/schema/inetorgperson.schema&lt;br /&gt;
 include /etc/ldap/schema/samba.schema&lt;br /&gt;
* now we create a working directory where &#039;&#039;slaptest&#039;&#039; can put our new LDIF file, and have &#039;&#039;slaptest&#039;&#039; create the configuration:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;mkdir /tmp/ldif_output&#039;&#039;&#039;&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;slaptest -f /etc/ldap/schema/schema_convert.conf -F /tmp/ldif_output&#039;&#039;&#039;&lt;br /&gt;
 config file testing succeeded&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
* The previous step has created a directory structure under &#039;&#039;/tmp/ldif_output&#039;&#039; that actually mirrors the config directory &#039;&#039;/etc/ldap/slapd.d/cn=config/cn=schema&#039;&#039;, but it contains a shiny new &#039;&#039;cn={4}samba.ldif&#039;&#039; file. We need to edit this file a bit before we can actually feed it to the LDAP server. Thus we&#039;ll edit it using (note the extra backslashes to escape the equal-sign and curly brackets):&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;vi /tmp/ldif_output/cn\=config/cn\=schema/cn\=\{4\}samba.ldif&#039;&#039;&#039;&lt;br /&gt;
* We need to change and edit some parts of &#039;&#039;cn={4}samba.ldif&#039;&#039;:&lt;br /&gt;
** Near the top we find &#039;&#039;dn: cn={4}samba&#039;&#039;. We&#039;ll change this to the correct distinguished name &#039;&#039;dn: cn=samba,cn=schema,cn=config&#039;&#039;&lt;br /&gt;
** Also near the top: &#039;&#039;cn: {4}samba&#039;&#039;. We&#039;ll change this to &#039;&#039;cn: samba&#039;&#039;&lt;br /&gt;
** The last seven lines look like the bit below - we need to remove these lines:&lt;br /&gt;
 structuralObjectClass: olcSchemaConfig&lt;br /&gt;
 entryUUID: f19250ba-1057-1031-88b7-8301a25f1d46&lt;br /&gt;
 creatorsName: cn=config&lt;br /&gt;
 createTimestamp: 20120401150603Z&lt;br /&gt;
 entryCSN: 20120401150603.478495Z#000000#000#000000&lt;br /&gt;
 modifiersName: cn=config&lt;br /&gt;
 modifyTimestamp: 20120401150603Z&lt;br /&gt;
* We&#039;ll store the cleaned up LDIF file in &#039;&#039;/etc/ldap/schema&#039;&#039; with the originating schema file&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;mv /tmp/ldif_output/cn\=config/cn\=schema/cn\=\{4\}samba.ldif /etc/ldap/schema/samba.ldif&#039;&#039;&#039;&lt;br /&gt;
root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
===Inserting the LDIF file in the LDAP server===&lt;br /&gt;
Time to actually invoke &#039;&#039;ldapadd&#039;&#039; which can put this schema in our LDAP server.&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapadd -QY EXTERNAL -H ldapi:/// -f /etc/ldap/schema/samba.ldif&#039;&#039;&#039;&lt;br /&gt;
 adding new entry &amp;quot;cn=samba,cn=schema,cn=config&amp;quot;&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenLDAP&amp;diff=3081</id>
		<title>OpenLDAP</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenLDAP&amp;diff=3081"/>
		<updated>2016-02-21T21:39:39Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Post-install reconfiguration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note: if you need information on the OpenLDAP version from Debian 5.0, see this page: [[OpenLDAP 2.4.11]]&lt;br /&gt;
&lt;br /&gt;
== OpenLDAP installation==&lt;br /&gt;
Note: we&#039;re going to install OpenLDAP on our server as [http://www.openldap.org/doc/admin24/config.html#Local%20Directory%20Service the local directory service], without replication, referrals or other advanced features. Under Debian Squeeze, this is OpenLDAP 2.4.23.&lt;br /&gt;
&lt;br /&gt;
===Standard installation===&lt;br /&gt;
Installing OpenLDAP on your Debian server is ridiculously simple. Just make sure your server is up-to-date (&#039;&#039;sudo apt-get update&#039;&#039; followed by &#039;&#039;sudo apt-get upgrade&#039;&#039;), and then install the two main components for your OpenLDAP server. First off: the LDAP client and utilities&lt;br /&gt;
 sudo apt-get install ldap-utils&lt;br /&gt;
This will result in the installation of as much as 8 different packages (&#039;&#039;ldap-utils&#039;&#039;, &#039;&#039;libgcrypt11&#039;&#039;, &#039;&#039;libgnutls26&#039;&#039;, &#039;&#039;libgpg-error0&#039;&#039;, &#039;&#039;libldap-2.4-2&#039;&#039;, &#039;&#039;libsasl2-2&#039;&#039;, &#039;&#039;libsasl2-modules&#039;&#039;, and &#039;&#039;libtasn1-3&#039;&#039;). Next the main component of an LDAP server installation, the stand-alone LDAP daemon &amp;quot;slapd&amp;quot;&lt;br /&gt;
 sudo apt-get install slapd&lt;br /&gt;
This may also install up to 8 packages (&#039;&#039;slapd&#039;&#039;, &#039;&#039;libltdl7&#039;&#039;, &#039;&#039;libperl5.10&#039;&#039;, &#039;&#039;libslp1&#039;&#039;, &#039;&#039;odbcinst&#039;&#039;, &#039;&#039;odbcinst1debian2&#039;&#039;, &#039;&#039;psmisc&#039;&#039; and &#039;&#039;unixodbc&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The Debian configuration script will ask you for only one single thing: an administrator password. As always: generate a strong password! After you&#039;ve provided the password, the LDAP database is created with the administrator name &amp;quot;admin&amp;quot; and as a base directory, something based on your DNS name. Suppose your internal domain is &amp;quot;amber.lan&amp;quot;, then the script will generate &#039;&#039;suffix &amp;quot;dc=amber,dc=lan&amp;quot;&#039;&#039;&amp;lt;ref&amp;gt;Should you see a third, empty, domain component (&#039;&#039;dc=&#039;&#039;) then this is caused by a trailing dot in your particular DNS name: the DNS root. You might have specified your domain as &amp;quot;amber.lan.&amp;quot;. You &#039;&#039;should&#039;&#039; change your domain name to a name without the DNS root, and you &#039;&#039;must&#039;&#039; regenerate your LDAP directory.&amp;lt;/ref&amp;gt;.&lt;br /&gt;
The above method of configuring yields you an LDAP database with only two objects in it. Suppose your DNS name is &amp;quot;easton2.amber.lan&amp;quot;, then the two objects are:&lt;br /&gt;
* a single Organization (o=&amp;quot;amber.lan&amp;quot;) with Distinguished Name dn=&amp;quot;dc=amber,dc=lan&amp;quot;&lt;br /&gt;
* a single administrator with Common Name cn=&amp;quot;admin&amp;quot;, and dn=&amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&lt;br /&gt;
Note, however, that there&#039;s &#039;&#039;also&#039;&#039; a second LDAP database, &amp;quot;cn=config&amp;quot;, which on your server is located under &#039;&#039;/etc/ldap/slapd.d&#039;&#039;. We&#039;ll cover what&#039;s in it further on.&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing the installation===&lt;br /&gt;
After installation of the package, it should automatically have been started, and should now be operational. This can be checked with a utility like &#039;&#039;nmap&#039;&#039;:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;nmap -p 389 localhost&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Starting Nmap 5.00 ( &amp;lt;nowiki&amp;gt;http://nmap.org&amp;lt;/nowiki&amp;gt; ) at 2011-04-13 21:19 CEST&lt;br /&gt;
 Interesting ports on localhost (127.0.0.1):&lt;br /&gt;
 PORT    STATE SERVICE&lt;br /&gt;
 389/tcp open  ldap  &lt;br /&gt;
 &lt;br /&gt;
 Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds&lt;br /&gt;
 root@easton2:~#&#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Another way to test if the LDAP server is functional, is by querying it with the &#039;&#039;ldapsearch&#039;&#039; utility, part of the package &#039;&#039;ldap-utils&#039;&#039;. Let&#039;s see if we can find the naming context of the LDAP server:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -x -b &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt; -s base &#039;(objectclass=*)&#039; namingContexts&#039;&#039;&#039;&lt;br /&gt;
 # extended LDIF&lt;br /&gt;
 #&lt;br /&gt;
 # LDAPv3&lt;br /&gt;
 # base &amp;lt;&amp;gt; with scope baseObject&lt;br /&gt;
 # filter: (objectclass=*)&lt;br /&gt;
 # requesting: namingContexts&lt;br /&gt;
 #&lt;br /&gt;
 &lt;br /&gt;
 #&lt;br /&gt;
 dn:&lt;br /&gt;
 namingContexts: dc=amber,dc=lan&lt;br /&gt;
 &lt;br /&gt;
 # search result&lt;br /&gt;
 search: 2&lt;br /&gt;
 result: 0 Success&lt;br /&gt;
 &lt;br /&gt;
 # numResponses: 2&lt;br /&gt;
 # numEntries: 1&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
With this command, we do a search using&lt;br /&gt;
* basic authentication (instead of one encrypted with SASL),&lt;br /&gt;
* searching within the LDAP tree from base &amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt; (meaning the absolute root of the tree),&lt;br /&gt;
* looking for base object only (instead of a one-level search, a subtree search, or a children-search),&lt;br /&gt;
* filtering for objects of any class,&lt;br /&gt;
* asking for the naming context of the result.&lt;br /&gt;
The output shows that the server responds; two objects have been considered, but none match the filter (that the object should have an objectClass).&lt;br /&gt;
&lt;br /&gt;
Let&#039;s now do the same but with authentication, to see if we can bind to the LDAP server. We&#039;ll first use an incorrect password, then the correct one:&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -W -D &amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 Enter LDAP Password:&lt;br /&gt;
 ldap_bind: Invalid credentials (49)&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;ldapsearch -W -D &amp;quot;cn=admin,dc=amber,dc=lan&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 Enter LDAP Password:&lt;br /&gt;
 # extended LDIF&lt;br /&gt;
 #&lt;br /&gt;
 # LDAPv3&lt;br /&gt;
 # base &amp;lt;&amp;gt; (default) with scope subtree&lt;br /&gt;
 # filter: (objectclass=*)&lt;br /&gt;
 # requesting: ALL&lt;br /&gt;
 #&lt;br /&gt;
 &lt;br /&gt;
 # search result&lt;br /&gt;
 search: 2&lt;br /&gt;
 result: 32 No such object&lt;br /&gt;
 &lt;br /&gt;
 # numResponses: 1&lt;br /&gt;
 root@easton2:~# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Finally, you could simply install and run a graphical management tool for LDAP servers, like [http://directory.apache.org/studio/ Apache Directory Studio]. Note however that if this check fails, then this could also mean problems with firewalls, network connections et cetera.&lt;br /&gt;
&lt;br /&gt;
===Post-install reconfiguration===&lt;br /&gt;
Since the default configuration with the server&#039;s DNS domain as LDAP base might not always be the most convenient configuration, you could run the configuration again using &#039;&#039;dpkg-reconfigure slapd&#039;&#039;. However, following this procedure is &#039;&#039;&#039;only&#039;&#039;&#039; necessary if you want to change any of the default installation values like the backend database type or DNS domain name; things like the organization name can be edited with other means, as will be shown later on.&lt;br /&gt;
&lt;br /&gt;
To be able to reconfigure the LDAP service, you can run the reconfiguration command &#039;&#039;sudo dpkg-reconfigure slapd&#039;&#039;. Contrary to some older versions of Debian, you do not need to manually stop the &#039;&#039;slapd&#039;&#039; daemon, and you don&#039;t need to manually remove the old configuration or database (in fact, if you do, then the &#039;&#039;slapd&#039;&#039; package will break, so you cannot easily remove it with APT tools). Interestingly enough, this reconfiguration asks you many &#039;&#039;more&#039;&#039; questions. The answers could look like this:&lt;br /&gt;
 omit OpenLDAP config:  no&lt;br /&gt;
 DNS domain name:       saruman.biz&lt;br /&gt;
 Organization name:     Saruman&lt;br /&gt;
 Administrator passwd:  wEt3udes&lt;br /&gt;
 Database backend:      MDB&lt;br /&gt;
 DB remove after purge: yes&lt;br /&gt;
 Move old DB:           yes&lt;br /&gt;
 Allow LDAPv2:          no&lt;br /&gt;
As you can see, the reconfiguration yields much more configuration options than plain installation - although really you&#039;ll probably answer most questions with their default values anyway. The above method of configuring yields you an LDAP database with only two objects in it:&lt;br /&gt;
* a single Organization (o=&amp;quot;Saruman&amp;quot;) with Distinguished Name dn=&amp;quot;dc=saruman,dc=biz&amp;quot;&lt;br /&gt;
* a single administrator with Common Name cn=&amp;quot;admin&amp;quot;, and dn=&amp;quot;cn=admin,dc=saruman,dc=biz&amp;quot;&lt;br /&gt;
Also note that the reconfiguration creates a backup of the &amp;quot;old&amp;quot; LDAP database in a directory with a name like &#039;&#039;/var/backups/unknown-2.4.23-7.ldapdb&#039;&#039;; if you just reconfigured after installation, then you probably don&#039;t need this backup, so you can remove it.&lt;br /&gt;
&lt;br /&gt;
The database that your OpenLDAP server uses is a standard Berkeley DB (BDB/HDB) database. Now we most likely will require some other databases as well in our server setup, something modern like PostgreSQL or MySQL - so why don&#039;t we configure our OpenLDAP to use this same database as well? For the answer, see [http://www.openldap.org/doc/admin24/intro.html#LDAP%20vs%20RDBMS here] - in short, the LDAP tree structure does not lend itself very well to inclusion in a modern relational database. Thus, we advise to stick with the Berkeley database provided with OpenLDAP. Now, for the database backend, we have the choice between two almost identical flavours:&lt;br /&gt;
* the &#039;&#039;bdb&#039;&#039; backend used to be the recommended primary backend for a normal slapd database. It uses the Oracle Berkeley DB package, referred to as &#039;&#039;BDB&#039;&#039;, to store data. It makes extensive use of indexing and caching to speed data access.&lt;br /&gt;
* the &#039;&#039;hdb&#039;&#039; backend is a variant of the &#039;&#039;bdb&#039;&#039; backend that uses a hierarchical database layout which supports subtree renames. It is otherwise identical to the &#039;&#039;bdb&#039;&#039; behavior, and all the same configuration options apply.&lt;br /&gt;
In Debian 6.0 &amp;quot;Squeeze&amp;quot; with OpenLDAP 2.4.23, HDB is the default backend.&lt;br /&gt;
&lt;br /&gt;
==OpenLDAP server configuration==&lt;br /&gt;
&amp;lt;small&amp;gt;(text from http://www.rjsystems.nl/en/2100-d6-openldap-provider.php)&amp;lt;/small&amp;gt; As of OpenLDAP 2.4.23-3, the &#039;&#039;slapd&#039;&#039; runtime configuration is fully LDAP-enabled. The default is to manage it using the standard LDAP operations with data in LDIF. The old &#039;&#039;slapd.conf&#039;&#039; format is still supported, but since that file must now be converted to the new &#039;&#039;slapd-config&#039;&#039; format to allow runtime changes to be saved, it seems likely that the developers will eventually phase it out. Therefore, we&#039;ll focus only on the new configuration method, the main advantage of which is that any changes made are immediately active, so it is no longer necessary to restart &#039;&#039;slapd&#039;&#039; after making configuration changes.&lt;br /&gt;
&lt;br /&gt;
The new configuration format uses a slapd backend database that is found in the &#039;&#039;/etc/ldap/slapd.d/&#039;&#039; directory. The configuration is stored as a special LDAP directory with a predefined schema and DIT, the root of which is called &#039;&#039;cn=config&#039;&#039;. If you go look there, you&#039;ll find that most parts of this LDAP directory consist of editable flat files.&lt;br /&gt;
&lt;br /&gt;
===Check the current LDAP configuration===&lt;br /&gt;
From the command line, there really are several ways to check the current LDAP configuration:&lt;br /&gt;
* from the server itself, you can use the trusty &#039;&#039;ldapsearch&#039;&#039; command, running under root: this&#039;ll authenticate with user ID 0. Filtering only for distinguished names:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn=module{0},cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={0}core,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={1}cosine,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={2}nis,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={3}inetorgperson,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcBackend={0}hdb,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={-1}frontend,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* to get an idea of what the &#039;&#039;cn=config&#039;&#039; database looks like &#039;&#039;within LDAP itself&#039;&#039;, you can run this command:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;slapcat -b cn=config&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 objectClass: olcGlobal&lt;br /&gt;
 cn: config&lt;br /&gt;
 olcArgsFile: /var/run/slapd/slapd.args&lt;br /&gt;
 olcLogLevel: none&lt;br /&gt;
 olcPidFile: /var/run/slapd/slapd.pid&lt;br /&gt;
 olcToolThreads: 1&lt;br /&gt;
 &#039;&#039;&#039;&#039;&#039;(more LDIF texts)&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
 entryUUID: f2a8f568-fa40-102f-8b9d-5d4cbccf32a9&lt;br /&gt;
 creatorsName: cn=admin,cn=config&lt;br /&gt;
 createTimestamp: 20110413174103Z&lt;br /&gt;
 entryCSN: 20110413174103.641065Z#000000#000#000000&lt;br /&gt;
 modifiersName: cn=admin,cn=config&lt;br /&gt;
 modifyTimestamp: 20110413174103Z&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
: As you can see, this generates a pretty large LDIF dump of the contents of the &#039;&#039;cn=config&#039;&#039; directory. Much of it consists of schema information. The LDAP configuration directives are attributes of the directory entries (objects) and most them start with the prefix &amp;quot;olc&amp;quot; (&#039;&#039;&#039;O&#039;&#039;&#039;pen&#039;&#039;&#039;L&#039;&#039;&#039;DAP &#039;&#039;&#039;C&#039;&#039;&#039;onfiguration). Also, some of the objects have names with numbers between curly brackets. This is to compensate for the fact that LDAP databases do not store their contents in any particular order; they are inherently unordered. The numbers constitute a numeric index to ensure a consistent order in the configuration database and thereby preserve all ordering dependencies. The index numbers, however, are generated automatically in the order they are created and usually do not have to be provided.&lt;br /&gt;
* you can see the configuration by browsing through all the plain-text flat files in &#039;&#039;/etc/ldap/slapd.d/&#039;&#039; and its subdirectories.&lt;br /&gt;
Note that by default there is no way to do this remotely. If you&#039;d like to browse this configuration using a GUI tool like [http://directory.apache.org/studio/ apache directory studio], don&#039;t bother. Debian sets the &#039;&#039;cn=config&#039;&#039; part of the database with a root user of &#039;&#039;cn=admin,cn=config&#039;&#039;, but without a password, so you cannot bind to the &#039;&#039;cn=config&#039;&#039; database as anything else than the local root user. Thus you cannot access the &#039;&#039;cn=config&#039;&#039; database by GUI.&lt;br /&gt;
&lt;br /&gt;
===Adding or modifying the cn=config admin password===&lt;br /&gt;
To add a password to the config RootDN, we first must generate one; for this we can use the &#039;&#039;slappasswd&#039;&#039; command. By default it&#039;ll create an SSHA password, but by specifying MD5 as hash (using &#039;&#039; -h {MD5}&#039;&#039;) it will create an MD5 encrypted password. The command interactively asks you for the password, and won&#039;t show you what you&#039;ve typed, so be precise:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;slappasswd -h {MD5}&#039;&#039;&#039;&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-enter new password:&lt;br /&gt;
 {MD5}d5axCh6gYGjhfK4PGs09us==&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Now we determine the DN (Distinguished Name) for the database that contains the RootDN password. We&#039;ll also check if there isn&#039;t a password in place already. To do this we used the following LDAP search command.&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b  cn=config olcRootDN=cn=admin,cn=config dn olcRootDN olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 olcRootDN: cn=admin,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the olcDatabase line, as it&#039;s the result we were looking for; it&#039;ll be needed for the &#039;&#039;ldapmodify&#039;&#039; command. Furthermore, note the absence of an olcRootPW entry; this is the starting point for a Debian OpenLDAP server.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can stick in a new password. If no password is present, you can use this interactive procedure:&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={0}config,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;add: olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcRootPW: {MD5}d5axCh6gYGjhfK4PGs09us==&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the following points:&lt;br /&gt;
* we use the olcDatabase location as found with the previous &#039;&#039;ldapsearch&#039;&#039; command;&lt;br /&gt;
* we input the MD5 password that we&#039;ve generated previously;&lt;br /&gt;
* as soon as you put in an empty line, the entry gets added;&lt;br /&gt;
* you have to use CTRL-D to end this interactive mode;&lt;br /&gt;
* if a password was already in place, we could still use the above, but we&#039;d interactively feed the second line as &#039;&#039;&#039;replace: olcRootPW&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
We could also put the password in an ldif file, and feed that to the server. To this end, we&#039;d create an ldif file with the following content:&lt;br /&gt;
 dn: olcDatabase={0}config,cn=config&lt;br /&gt;
 changetype: modify&lt;br /&gt;
 add: olcRootPW&lt;br /&gt;
 olcRootPW: {MD5}d5axCh6gYGjhfK4PGs09us==&lt;br /&gt;
If this file is called &#039;&#039;addpassword.ldif&#039;&#039; and is created in &#039;&#039;/tmp&#039;&#039;, then the addition can be executed using&lt;br /&gt;
 root@easton2:/etc/ldap# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/addpassword.ldif&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Adding or modifying (configuration) information==&lt;br /&gt;
The simple way of changing anything in the database goes like this:&lt;br /&gt;
===Method 1: interactive CLI tool===&lt;br /&gt;
As an example, let&#039;s add an index to the configuration. We&#039;ll start by seeing which indices already exist, then interactively add two indices. Finally, we check that the indices are there:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}hdb olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 olcDbIndex: objectClass eq&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={1}hdb,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;add: olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcDbIndex: cn eq&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcDbIndex: uid eq&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={1}hdb,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}hdb olcDbIndex&#039;&#039;&#039;&lt;br /&gt;
 dn: olcDatabase={1}hdb,cn=config&lt;br /&gt;
 olcDbIndex: objectClass eq&lt;br /&gt;
 olcDbIndex: cn eq&lt;br /&gt;
 olcDbIndex: uid eq&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
(And ofcourse we press ctrl-D to end interactive mode).&amp;lt;br&amp;gt;Note: we can /modify multiple attributes in one stanza, but we can also add multiple objects/attributes in one &#039;&#039;ldapmodify&#039;&#039; session:&lt;br /&gt;
* If you input an empty line, you can start another &#039;&#039;dn:&#039;&#039; line, and perform another action;&lt;br /&gt;
* If you input a minus sign by itself on a line, then OpenLDAP will assume you&#039;ll be performing another action in/on the same object.&lt;br /&gt;
&lt;br /&gt;
Modifying works almost the same; we only need keyword &#039;&#039;replace&#039;&#039; instead of &#039;&#039;add&#039;&#039;:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config -s base olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 olcLogLevel: none&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;changetype: modify&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;replace: olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;olcLogLevel: stats&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=config -s base olcLogLevel&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=config&lt;br /&gt;
 olcLogLevel: stats&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
Note the &#039;&#039;-s base&#039;&#039; option that limits the search for the &#039;&#039;olcLogLevel&#039;&#039; attribute to the &#039;&#039;cn=config&#039;&#039; container.&lt;br /&gt;
&lt;br /&gt;
Deleting information from an LDAP tree rarely ever happens, because once an attribute is used for anything, you aren&#039;t allowed to delete it, only modify it. However, if you want to delete anything, you can use the changetype &amp;quot;modify&amp;quot; with action &amp;quot;delete&amp;quot;:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapmodify -Y EXTERNAL -H ldapi:///&#039;&#039;&#039;&lt;br /&gt;
 SASL/EXTERNAL authentication started&lt;br /&gt;
 SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth&lt;br /&gt;
 SASL SSF: 0&lt;br /&gt;
 &#039;&#039;&#039;dn: olcDatabase={0}config,cn=config&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;changetype: modify&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;delete: olcRootPW&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
 modifying entry &amp;quot;olcDatabase={0}config,cn=config&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Method 2: use an ldif file===&lt;br /&gt;
===Method 3: use an LDAP browser===&lt;br /&gt;
With this method, you just use your LDAP browser for the addition or modification, according to its specific usage instructions. In the back, the tool will communicate with the LDAP server as you would in the previous methods. Note however, that this method relies on a bind account in the configuration database, which is a serious security risk.&lt;br /&gt;
&lt;br /&gt;
==Adding schemas==&lt;br /&gt;
A major task in LDAP maintenance is the addition of LDAP schemas. By default, only 4 schemas will be present in your LDAP server: &#039;&#039;core&#039;&#039;, &#039;&#039;cosine&#039;&#039;, &#039;&#039;nis&#039;&#039; and &#039;&#039;inetorgperson&#039;&#039;. Any other schema, -- say, for Samba -- would need to be added.&lt;br /&gt;
===Checking existing schemas===&lt;br /&gt;
Let&#039;s first check which schemas are already installed. Let&#039;s try two different methods, and see what they&#039;ll show out of the box:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapsearch -LLLQY EXTERNAL -H ldapi:/// -b cn=schema,cn=config &amp;quot;(objectClass=olcSchemaConfig)&amp;quot; dn&#039;&#039;&#039;&lt;br /&gt;
 dn: cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={0}core,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={1}cosine,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={2}nis,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 dn: cn={3}inetorgperson,cn=schema,cn=config&lt;br /&gt;
 &lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ls -l /etc/ldap/slapd.d/cn=config/cn=schema&#039;&#039;&#039;&lt;br /&gt;
 total 40&lt;br /&gt;
 -rw------- 1 openldap openldap 15474 Jun 13 17:39 cn={0}core.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap 11308 Jun 13 17:39 cn={1}cosine.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap  6438 Jun 13 17:39 cn={2}nis.ldif&lt;br /&gt;
 -rw------- 1 openldap openldap  2802 Jun 13 17:39 cn={3}inetorgperson.ldif&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
===Creating a suitable LDIF file for the schema===&lt;br /&gt;
To add a schema, you need a schema in LDIF format, which you can then add to the LDAP database using the &#039;&#039;ldapadd&#039;&#039; command.&lt;br /&gt;
Suppose you have a schema file &#039;&#039;samba.schema&#039;&#039; which you&#039;ve copied to the &#039;&#039;/etc/ldap/schema&#039;&#039; directory. You&#039;d first have to convert this to a suitable LDIF file. This can be done using &#039;&#039;slaptest&#039;&#039;, however &#039;&#039;slaptest&#039;&#039; requires access to the other schemas that your new schema is building on. So we now do this:&lt;br /&gt;
* We create a file &#039;&#039;schema_convert.conf&#039;&#039; with the content shown below. Note that we&#039;re including the schema files of all the schemas that are already in our LDAP server. Furthermore, because we may need it again with the next schema addition, it makes sense to save this file under &#039;&#039;/etc/ldap/schema&#039;&#039;:&lt;br /&gt;
 include /etc/ldap/schema/core.schema&lt;br /&gt;
 include /etc/ldap/schema/cosine.schema&lt;br /&gt;
 include /etc/ldap/schema/nis.schema&lt;br /&gt;
 include /etc/ldap/schema/inetorgperson.schema&lt;br /&gt;
 include /etc/ldap/schema/samba.schema&lt;br /&gt;
* now we create a working directory where &#039;&#039;slaptest&#039;&#039; can put our new LDIF file, and have &#039;&#039;slaptest&#039;&#039; create the configuration:&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;mkdir /tmp/ldif_output&#039;&#039;&#039;&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;slaptest -f /etc/ldap/schema/schema_convert.conf -F /tmp/ldif_output&#039;&#039;&#039;&lt;br /&gt;
 config file testing succeeded&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
* The previous step has created a directory structure under &#039;&#039;/tmp/ldif_output&#039;&#039; that actually mirrors the config directory &#039;&#039;/etc/ldap/slapd.d/cn=config/cn=schema&#039;&#039;, but it contains a shiny new &#039;&#039;cn={4}samba.ldif&#039;&#039; file. We need to edit this file a bit before we can actually feed it to the LDAP server. Thus we&#039;ll edit it using (note the extra backslashes to escape the equal-sign and curly brackets):&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;vi /tmp/ldif_output/cn\=config/cn\=schema/cn\=\{4\}samba.ldif&#039;&#039;&#039;&lt;br /&gt;
* We need to change and edit some parts of &#039;&#039;cn={4}samba.ldif&#039;&#039;:&lt;br /&gt;
** Near the top we find &#039;&#039;dn: cn={4}samba&#039;&#039;. We&#039;ll change this to the correct distinguished name &#039;&#039;dn: cn=samba,cn=schema,cn=config&#039;&#039;&lt;br /&gt;
** Also near the top: &#039;&#039;cn: {4}samba&#039;&#039;. We&#039;ll change this to &#039;&#039;cn: samba&#039;&#039;&lt;br /&gt;
** The last seven lines look like the bit below - we need to remove these lines:&lt;br /&gt;
 structuralObjectClass: olcSchemaConfig&lt;br /&gt;
 entryUUID: f19250ba-1057-1031-88b7-8301a25f1d46&lt;br /&gt;
 creatorsName: cn=config&lt;br /&gt;
 createTimestamp: 20120401150603Z&lt;br /&gt;
 entryCSN: 20120401150603.478495Z#000000#000#000000&lt;br /&gt;
 modifiersName: cn=config&lt;br /&gt;
 modifyTimestamp: 20120401150603Z&lt;br /&gt;
* We&#039;ll store the cleaned up LDIF file in &#039;&#039;/etc/ldap/schema&#039;&#039; with the originating schema file&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;mv /tmp/ldif_output/cn\=config/cn\=schema/cn\=\{4\}samba.ldif /etc/ldap/schema/samba.ldif&#039;&#039;&#039;&lt;br /&gt;
root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
===Inserting the LDIF file in the LDAP server===&lt;br /&gt;
Time to actually invoke &#039;&#039;ldapadd&#039;&#039; which can put this schema in our LDAP server.&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;ldapadd -QY EXTERNAL -H ldapi:/// -f /etc/ldap/schema/samba.ldif&#039;&#039;&#039;&lt;br /&gt;
 adding new entry &amp;quot;cn=samba,cn=schema,cn=config&amp;quot;&lt;br /&gt;
 root@easton2:/tmp# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3080</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3080"/>
		<updated>2016-02-21T15:17:51Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Configuring PuTTy to use the SSH key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using SSH keys for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSH keys to the mix.&lt;br /&gt;
&lt;br /&gt;
What we&#039;re going to do is create an SSH key pair: a public key that we can store on the server, and a private key that we&#039;ll use on our end when we connect with the server.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the public key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key &#039;&#039;file&#039;&#039;, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window - which is the public key, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a side note, if you need the &#039;&#039;private&#039;&#039; key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:wq&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next section).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information. To this end, put your private key in a secure spot accessible from your system. For example, on a secure (encrypted) USB stick. In this example I use a subdirectory of the Documents directory, named Keychain.&lt;br /&gt;
Now configure your PuTTy connection like you always would, but also go to the settings category Connection, subsection SSH, subsection Auth. There you&#039;ll find a Private key file section, from which you can browse to your .ppk private key file. It should look like this:&lt;br /&gt;
[[File:Puttyprivatekey.png|467px]]&lt;br /&gt;
&lt;br /&gt;
Then go back to the Session category to get to the PuTTy &amp;quot;main&amp;quot; screen, and hit Save. That&#039;s it. You can now log on to your server using PuTTy, and when connecting Putty will ask for the passphrase, but not for any password local to the server.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3079</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3079"/>
		<updated>2016-02-21T15:16:20Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Configuring PuTTy to use the SSH key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using SSH keys for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSH keys to the mix.&lt;br /&gt;
&lt;br /&gt;
What we&#039;re going to do is create an SSH key pair: a public key that we can store on the server, and a private key that we&#039;ll use on our end when we connect with the server.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the public key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key &#039;&#039;file&#039;&#039;, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window - which is the public key, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a side note, if you need the &#039;&#039;private&#039;&#039; key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:wq&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next section).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information. To this end, put your private key in a secure spot accessible from your system. For example, on a secure (encrypted) USB stick. In this example I use a subdirectory of the Documents directory, named Keychain.&lt;br /&gt;
Now configure your PuTTy connection like you always would, but also go to the settings category Connection, subsection SSH, subsection Auth. There you&#039;ll find a Private key file section, from which you can browse to your .ppk private key file. It should look like this:&lt;br /&gt;
[[File:Puttyprivatekey.png|467px]]&lt;br /&gt;
&lt;br /&gt;
That&#039;s it. You can now log on to your server using PuTTy, and when connecting Putty will ask for the passphrase, but not for any password local to the server.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3078</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3078"/>
		<updated>2016-02-21T15:16:05Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Configuring PuTTy to use the SSH key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using SSH keys for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSH keys to the mix.&lt;br /&gt;
&lt;br /&gt;
What we&#039;re going to do is create an SSH key pair: a public key that we can store on the server, and a private key that we&#039;ll use on our end when we connect with the server.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the public key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key &#039;&#039;file&#039;&#039;, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window - which is the public key, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a side note, if you need the &#039;&#039;private&#039;&#039; key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:wq&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next section).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information. To this end, put your private key in a secure spot accessible from your system. For example, on a secure (encrypted) USB stick. In this example I use a subdirectory of the Documents directory, named Keychain.&lt;br /&gt;
Now configure your PuTTy connection like you always would, but also go to the settings category Connection, subsection SSH, subsection Auth. There you&#039;ll find a Private key file section, from which you can browse to your .ppk private key file. It should look like this:&lt;br /&gt;
[[File:Puttyprivatekey.png|467px]]&lt;br /&gt;
That&#039;s it. You can now log on to your server using PuTTy, and when connecting Putty will ask for the passphrase, but not for any password local to the server.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=File:Puttyprivatekey.png&amp;diff=3077</id>
		<title>File:Puttyprivatekey.png</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=File:Puttyprivatekey.png&amp;diff=3077"/>
		<updated>2016-02-21T15:09:28Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: Example for PuTTy config&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Example for PuTTy config&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3076</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3076"/>
		<updated>2015-12-16T15:28:57Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: typo&amp;#039;s&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using SSH keys for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSH keys to the mix.&lt;br /&gt;
&lt;br /&gt;
What we&#039;re going to do is create an SSH key pair: a public key that we can store on the server, and a private key that we&#039;ll use on our end when we connect with the server.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the public key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key &#039;&#039;file&#039;&#039;, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window - which is the public key, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a side note, if you need the &#039;&#039;private&#039;&#039; key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:wq&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next section).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3075</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3075"/>
		<updated>2015-09-04T19:07:05Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users. If you are interested in my work on [http://www.dya.info DYA|Infrastructure], please visit the [https://dya-knowledge.sogeti.nl/ SmartMart demo site].&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian Jessie base server|Debian 8 Jessie base server]] is a howto on the installation of a very basic Linux box under Jessie (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; and &#039;&#039;btrfs&#039;&#039; for [[software-based RAID]] contains our ideas and observations on data redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication and security&#039;&#039;&#039;&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your own LAMP server&#039;&#039;&#039;&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Other server apps&#039;&#039;&#039;&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
* How to create [[your own ownCloud]] server (and here&#039;s [http://www.thecomputerkid.com/2013/06/why-you-should-use-owncloud.html why] you should do this)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Big_Bag%27o%27utilities&amp;diff=3074</id>
		<title>Big Bag&#039;o&#039;utilities</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Big_Bag%27o%27utilities&amp;diff=3074"/>
		<updated>2015-06-17T10:51:07Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: nicer layout&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;All utilities listed below are command line utilities; install them using &#039;&#039;apt-get install&#039;&#039; or &#039;&#039;aptitude&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;apticron&#039;&#039; checks your system daily, and mails you when there are updates for packages&lt;br /&gt;
* &#039;&#039;ccze&#039;&#039; can &amp;quot;colorize&amp;quot; output, e.g. &#039;&#039;tail -f /var/log/syslog | ccze&#039;&#039;&lt;br /&gt;
* &#039;&#039;[http://packages.debian.org/ethtool ethtool]&#039;&#039; can change settings for ethernet cards, like speed and duplex&lt;br /&gt;
* &#039;&#039;ipcalc&#039;&#039; is an IP address/mask calculator&lt;br /&gt;
* (&#039;&#039;[[IProute | iproute]]&#039;&#039; helps viewing and setting the [http://lartc.org/ IP configuration] - under Lenny it&#039;s installed by default, under Etch you&#039;ll have to do it yourself)&lt;br /&gt;
* &#039;&#039;iptraf&#039;&#039; is an IP traffic monitor&lt;br /&gt;
* &#039;&#039;less&#039;&#039; is a utility [http://blog.platinumsolutions.com/node/47 to view text files];&lt;br /&gt;
* &#039;&#039;lsof&#039;&#039; can show all open files&lt;br /&gt;
* &#039;&#039;multitail&#039;&#039; can follow multiple (log)files in one terminal&lt;br /&gt;
* &#039;&#039;pwgen&#039;&#039; is a password generator&lt;br /&gt;
* &#039;&#039;[[Sudo | sudo]]&#039;&#039; enables you to execute commands with another user&#039;s credentials&lt;br /&gt;
* &#039;&#039;[[TCPdump | tcpdump]] is a network sniffer&lt;br /&gt;
* &#039;&#039;pciutils&#039;&#039; contains the &#039;&#039;lspci&#039;&#039; command, which can be useful to review your hardware&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The following are compression and archiving tools:&lt;br /&gt;
* &#039;&#039;arj&#039;&#039; is a tool for the .arj file format&lt;br /&gt;
* &#039;&#039;bzip2&#039;&#039; is for .bz2 files&lt;br /&gt;
* &#039;&#039;p7zip&#039;&#039; is for .7z archives&lt;br /&gt;
* &#039;&#039;unzip&#039;&#039; is for the .zip file format&lt;br /&gt;
* &#039;&#039;xz-utils&#039;&#039; is a toolkit for LZ/M compression; adding it will make &#039;&#039;tar&#039;&#039; understand .xz files&lt;br /&gt;
* &#039;&#039;zoo&#039;&#039; is for the .zoo file format&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Big_Bag%27o%27utilities&amp;diff=3073</id>
		<title>Big Bag&#039;o&#039;utilities</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Big_Bag%27o%27utilities&amp;diff=3073"/>
		<updated>2015-06-17T10:48:45Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: added p7zip and xz-utils&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;All utilities listed below are command line utilities; install them using &#039;&#039;apt-get install&#039;&#039; or &#039;&#039;aptitude&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;apticron&#039;&#039; checks your system daily, and mails you when there are updates for packages&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;ccze&#039;&#039; can &amp;quot;colorize&amp;quot; output, e.g. &#039;&#039;tail -f /var/log/syslog | ccze&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;[http://packages.debian.org/ethtool ethtool]&#039;&#039; can change settings for ethernet cards, like speed and duplex&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;ipcalc&#039;&#039; is an IP address/mask calculator&amp;lt;br&amp;gt;&lt;br /&gt;
(&#039;&#039;[[IProute | iproute]]&#039;&#039; helps viewing and setting the [http://lartc.org/ IP configuration] - under Lenny it&#039;s installed by default, under Etch you&#039;ll have to do it yourself)&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;iptraf&#039;&#039; is an IP traffic monitor&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;less&#039;&#039; is a utility [http://blog.platinumsolutions.com/node/47 to view text files];&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;lsof&#039;&#039; can show all open files&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;multitail&#039;&#039; can follow multiple (log)files in one terminal&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;pwgen&#039;&#039; is a password generator&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;[[Sudo | sudo]]&#039;&#039; enables you to execute commands with another user&#039;s credentials&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;[[TCPdump | tcpdump]] is a network sniffer&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;pciutils&#039;&#039; contains the &#039;&#039;lspci&#039;&#039; command, which can be useful to review your hardware&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following are compression and archiving tools:&lt;br /&gt;
&#039;&#039;arj&#039;&#039; is a tool for the .arj file format&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;bzip2&#039;&#039; is for .bz2 files&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;p7zip&#039;&#039; is for .7z archives&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;unzip&#039;&#039; is for the .zip file format&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;xz-utils&#039;&#039; is a toolkit for LZ/M compression; adding it will make &#039;&#039;tar&#039;&#039; understand .xz files&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;zoo&#039;&#039; is for the .zoo file format&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3072</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3072"/>
		<updated>2015-06-16T20:16:42Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: text&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users. If you are interested in my work on [http://www.dya.info DYA|Infrastructure], please visit the [https://dya-knowledge.sogeti.nl/ SmartMart demo site].&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian Jessie base server]] is a howto on the installation of a very basic Linux box under Jessie (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; and &#039;&#039;btrfs&#039;&#039; for [[software-based RAID]] contains our ideas and observations on data redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication and security&#039;&#039;&#039;&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your own LAMP server&#039;&#039;&#039;&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Other server apps&#039;&#039;&#039;&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
* How to create [[your own ownCloud]] server (and here&#039;s [http://www.thecomputerkid.com/2013/06/why-you-should-use-owncloud.html why] you should do this)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3071</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3071"/>
		<updated>2015-06-16T20:10:39Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: link to Jessie server&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users. If you are interested in my work on [http://www.dya.info DYA|Infrastructure], please visit the [https://dya-knowledge.sogeti.nl/ SmartMart demo site].&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian_Jessie_base_server]] is a howto on the installation of a very basic Linux box under Jessie (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; for [[software-based RAID]] contains our ideas and observations on redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication and security&#039;&#039;&#039;&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your own LAMP server&#039;&#039;&#039;&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Other server apps&#039;&#039;&#039;&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
* How to create [[your own ownCloud]] server (and here&#039;s [http://www.thecomputerkid.com/2013/06/why-you-should-use-owncloud.html why] you should do this)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Debian_Jessie_base_server&amp;diff=3070</id>
		<title>Debian Jessie base server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Debian_Jessie_base_server&amp;diff=3070"/>
		<updated>2015-06-16T20:09:51Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: branched off of old Wheezy base server page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
==Hardware preparation==&lt;br /&gt;
When installing a new server, you must begin with [[Server hardware prep|getting your server hardware right]]. Assuming you&#039;ve built yourself a new server platform, you can install the operating system following the steps outlined below. Note: it is assumed the server is bare, and the hard disks are completely clean. If they are not, here&#039;s how to [[Cleaning a hard disk|clean]] them.&lt;br /&gt;
&lt;br /&gt;
==Planning your network names==&lt;br /&gt;
If your machine must become a part of an existing network, then it&#039;s almost certain that you already have a DNS domain in place; in that case: obtain the DNS suffix your machine will get (the DNS domain your machine will &amp;quot;belong&amp;quot; to). However, it&#039;s also possible that this machine is going to be the first machine in your new network, in which case the whole issue of DNS suffixes is wide open. If you need more information on DNS, go [[https://kb.isc.org/article/AA-01031 here]]. For now we&#039;ll assume you have (or will quickly obtain) a working knowledge of the DNS system. &lt;br /&gt;
Here is our tip on choosing a DNS domain for your home network:&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; use a publicly registered domain name (e.g. &amp;quot;cocacola.com&amp;quot;) for any machine that&#039;s not primarily intended to serve the public on the Internet;&lt;br /&gt;
* for machines serving a private network, we urge you to use Top Level Domain name &amp;quot;lan&amp;quot; (to signify your machine is on a Local Area Network or LAN)&lt;br /&gt;
* for the Domain Name itself, we suggest you use a level 2 name, like &amp;quot;saruman.lan&amp;quot;, and not a level 3 name, like &amp;quot;mister.saruman.lan&amp;quot;.&lt;br /&gt;
This is only a short section on DNS, but remember that once a proper DNS system is in place, it&#039;s pretty much work to change it. At any rate, this section has most likely showed you that you need to put some thought into the DNS Domain Name design of your home network.&lt;br /&gt;
OK, with this out of the way, we can get to installing the OS.&lt;br /&gt;
&lt;br /&gt;
==Operating System installation==&lt;br /&gt;
===Preparing to boot into the installer===&lt;br /&gt;
To install an Operating System (OS), it&#039;s kinda instrumental that you have one. Here, we&#039;re going to use [http://www.debian.org/intro/about Debian], the biggest [http://www.debian.org/intro/about#free Free] OS that we know of. Free stands for Freedom, but incidentally that Freedom also means it&#039;s gratis, an appealing aspect of Free. To get your own copy of Debian, go to their [http://www.debian.org/distrib/ download site] and obtain the latest [http://www.debian.org/releases/ Stable] image - as of april 2015, it&#039;s Debian 8, or &amp;quot;Jessie&amp;quot; as it&#039;s also known.&lt;br /&gt;
&lt;br /&gt;
Besides the choice which release of Debian you want to run, you also have to know for which platform you&#039;re downloading (in our case: either &#039;&#039;amd64&#039;&#039; or &#039;&#039;i386&#039;&#039; depending on your hardware platform) and what kind of install you wish - if you have a working, fast Internet connection available at the time of install, then we recommend getting the [https://www.debian.org/CD/netinst/ netinst] CD image; it&#039;s a relatively small CD, that&#039;ll be able to get you going, but gets most of the software you&#039;ll need straight from the &#039;net at install time.&lt;br /&gt;
&lt;br /&gt;
In the example at hand we&#039;re installing on an Intel Atom C2000-based server, on which we wish to install 64-bits software. We&#039;ll download [http://cdimage.debian.org/debian-cd/8.1.0/amd64/iso-cd/debian-8.1.0-amd64-netinst.iso debian-8.1.0-amd64-netinst.iso], which is Jessie after its first update. If you wish, you can burn this to a CD-recordable and boot your prepared hardware platform from this CD. As it stands, we can boot our server platform from the iso file directly by sharing the image using SaMBa, then mounting that fileshared image in the server hardware console - we&#039;re lucky that way not needing physical CDs :-)&lt;br /&gt;
&lt;br /&gt;
===Installer===&lt;br /&gt;
After booting from the CD, a friendly graphic screen shows you the Installer boot menu. Your choices are:&lt;br /&gt;
* Install, the default non-graphical installation;&lt;br /&gt;
* Graphical install, so you can click things;&lt;br /&gt;
* Advanced options, where you can select expert options like the rescue mode;&lt;br /&gt;
* Help; this drops you to a non-graphical screen where you can select help texts by using function keys. The screens explain how you can start the installation with extra parameters to instruct Debian to handle your hardware in a non-standard way, e.g. on an old machine with a problematic videocard you could run &amp;quot;install vga=771&amp;quot; (for some laptops) or &amp;quot;install vga=normal fb=false&amp;quot; (to disable the screen framebuffer).&lt;br /&gt;
We&#039;re going to use the standard Command Line installation, so we choose &amp;quot;Install&amp;quot; and hit &amp;amp;lt;enter&amp;amp;gt;.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; |-&lt;br /&gt;
|We could easily use &amp;quot;Graphic install&amp;quot;, in which case we&#039;d have a nice fresh Graphical User Interface for our installation. &#039;&#039;We&#039;re&#039;&#039; not going to, because we&#039;re real men, and Real Men Don&#039;t Click. Also, we&#039;ve found that from the GUI it&#039;s a bit harder to switch to a second console and then back.&lt;br /&gt;
We could also go to the Advanced options, and opt for &amp;quot;Expert install&amp;quot; or &amp;quot;Graphical expert install&amp;quot; as installation method, because it gives a much finer grain of control; however we usually don&#039;t need that control, and can do just fine without the barrage of extra questions that the &amp;quot;expert&amp;quot; installation method pose.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After the Linux kernel finishes initializing the machine, a simple text-based installer appears that immediately starts asking questions. Answer them according to your needs. Our example system uses the following choices:&lt;br /&gt;
* Language: English&lt;br /&gt;
* country: other &amp;amp;gt; Europe &amp;amp;gt; Netherlands&lt;br /&gt;
* locale (since there&#039;s no default locale for the combination Netherlands/English): United States - en_US.UTF-8&lt;br /&gt;
* keymap: American English (since we have a keyboard with US layout)&lt;br /&gt;
Some installation software loads, and we get to the next phase: if you have multiple NICs in your machine (which we believe you &#039;&#039;should&#039;&#039; have), and if they&#039;re detected properly, then you&#039;re required to indicate which of the detected network interface cards (NIC) is going to be the &amp;quot;primary&amp;quot; NIC.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; |-&lt;br /&gt;
|Here, trouble could begin. If your machine has only network cards that are &#039;&#039;&#039;not&#039;&#039;&#039; supported, then you&#039;ll see &#039;&#039;&#039;no&#039;&#039;&#039; cards here - but then how are you going to do a NetInstall? A solution would be to (temporarily) install a NIC that &#039;&#039;is&#039;&#039; supported, like a cheap Realtek card, or an ancient 3Com 905 card. Then, when the whole system is installed, up and running, you could compile a new kernel that contains support for your actual NICs, and when these work, remove the temporary NIC. For now, we&#039;ll assume that at least one of your NICs is recognised properly by the Debian installation routine.&lt;br /&gt;
|}&lt;br /&gt;
Select the card that&#039;s connected and has (indirect) access to Internet (again: it should &#039;&#039;not&#039;&#039; be connected straight to the wild wild web, but sit safely behind a firewall, at least until we&#039;ve installed our own firewall); if at all possible, let it be the NIC that&#039;ll be connected to your home network itself, on the &#039;&#039;inside&#039;&#039; of your server. Let&#039;s assume that this NIC is designated &#039;&#039;eth0&#039;&#039; by the Debian installation. This card will now be configured using DHCP, so if you&#039;re on a network with a DHCP-server, the network will work straight away. If it&#039;s not, you can either configure the network configuration manually, or fix your DHCP-server and connection between it and &#039;&#039;eth0&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Next is one of the hardest questions that any OS installation is going to ask you: what will be the host name of the system? You could easily change it at any time in the future, but possibly with lots of hassle, so you better choose wisely. Here are our tips:&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; name your machine after the user that&#039;s going to use it, e.g. &amp;quot;bernie-pc&amp;quot; (at some time in the future, Bernie&#039;s machine will be moved to Alice, so then Alice is working on &amp;quot;bernie-pc&amp;quot; which makes the situation quite unclear);&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; name your machine after the department or workgroup that&#039;s using it most, e.g. &amp;quot;accounting-srv&amp;quot; (same reasoning);&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; name your machine after it&#039;s main function, e.g. &amp;quot;printserver&amp;quot; (at some time in the future, the main function is moved to another machine, and/or an alternative function will become the main function of the machine);&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; name your machine after it&#039;s location, e.g. &amp;quot;srv-boston&amp;quot; (at some time in the future, the box will be moved to another location);&lt;br /&gt;
* do &#039;&#039;&#039;not&#039;&#039;&#039; name your machine after it&#039;s hardware configuration, e.g. &amp;quot;ibmx346&amp;quot; (at some time in the future, either another xSeries x346 will be wheeled in, or the machine will be upgraded to accommodate increased use or overcome hardware problems - your &amp;quot;ibmx346&amp;quot; could suddenly be running on an xSeries x3650).&lt;br /&gt;
What we feel are safe names for &#039;&#039;any&#039;&#039; machine in your network are true names, perhaps linked to a common theme: names of European cities, names of movie characters, names of countries or holiday destinations et cetera. Less imaginative would be coded names like &amp;quot;server0001&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Immediately following comes the question of the Domain Name. This is about a DNS domain, so effectively the installation program is asking which DNS suffix the host name should have; if the DHCP-server already provided something it&#039;ll be suggested, but you can override it if need be. In the preparatory phase, you&#039;ll have decided on continuation of your current DNS schema, or starting a new one. Either way, put the chosen DNS suffix in and press &amp;amp;lt;enter&amp;amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next comes one &#039;&#039;&#039;VERY&#039;&#039;&#039; important question: what to use as root password? We cannot stress this enough: choose a SAFE password! Do NOT go for an easy-to-remember one, go for STRONG and SAFE. There are tools to help you generate strong passwords, like [https://identitysafe.norton.com/password-generator/ this page]: use them! We strongly suggest 10 characters or more, including letters, mixed case, and numbers, so something like &#039;&#039;SuCRe4hecH&#039;&#039; (do NOT use this, generate your own!).&lt;br /&gt;
&lt;br /&gt;
Next, give the full name of the principal user of this server (your own, we assume), give the login-name (your given name, we assume), and a corresponding password. Again, use a SAFE password. As long as you don&#039;t make your principal user equivalent to root, you might go for a slightly weaker password (8 characters instead of 10), but we rather suggest you make the password just as strong (and different from!) the root password.&lt;br /&gt;
&lt;br /&gt;
After entering the details of these two users &amp;quot;root&amp;quot; and &amp;quot;you&amp;quot;, we get to the server hardware.&lt;br /&gt;
&lt;br /&gt;
===Partitioning===&lt;br /&gt;
Now comes the question of partitioning, or how to divide the available disk space into chunks for the server to use. This is a tricky subject, because if you put all storage space into one partition, then some day a runaway process will fill up the entire disk with useless logs, and the system will crash. On the other hand, if you divvy up all space into little chunks, then some application is going to need space in one of those partitions where there is none, even though there may be plenty in other partitions.&lt;br /&gt;
To minimize the chance of either problem occurring, we&#039;re going to use [http://tldp.org/HOWTO/LVM-HOWTO/whatisvolman.html Logical Volume Management (LVM2)] so that we can provision enough space to start our server, but keep some space in reserve to apply when needed, where it&#039;ll be needed.&lt;br /&gt;
&lt;br /&gt;
So, we at Saruman.biz have put together a recommended standard partitioning scheme. The basis (in accordance with the standard [[Debian directory structure]] is this:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot;&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Partition&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|MD&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|LVG&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|LV-name&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Size &amp;lt;br&amp;gt; (physical machine)&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Size (VM)&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|File System&lt;br /&gt;
!style=&amp;quot;background:#ffdead;&amp;quot;|Mount point&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| /dev/md0&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| 100MiB&lt;br /&gt;
| 100MiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /boot&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| /dev/md1&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| 3GiB&lt;br /&gt;
| 1GiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;8&amp;quot; valign=&amp;quot;top&amp;quot; | 3&lt;br /&gt;
| rowspan=&amp;quot;8&amp;quot; valign=&amp;quot;top&amp;quot; | /dev/md2&lt;br /&gt;
| rowspan=&amp;quot;8&amp;quot; valign=&amp;quot;top&amp;quot; style=&amp;quot;background:lightgrey&amp;quot;| system&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | swap&lt;br /&gt;
| 1GiB&amp;lt;ref name=&amp;quot;swap&amp;quot;&amp;gt;Rule of thumb: twice the size of the machine&#039;s RAM, but no less than 256MiB and no more than 2GiB&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 256MiB&amp;lt;ref name=&amp;quot;swap&amp;quot;/&amp;gt;&lt;br /&gt;
| swap&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | var&lt;br /&gt;
| 1GiB&lt;br /&gt;
| 512MiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /var&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | varlog&lt;br /&gt;
| 1GiB&lt;br /&gt;
| 512MiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /var/log&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | appslog&lt;br /&gt;
| 3GiB&lt;br /&gt;
| -&amp;lt;ref&amp;gt;Yes, we think a separate &#039;&#039;appslog&#039;&#039; is a very good idea, but when creating a minimal VM, we have to save disk space &#039;&#039;somewhere&#039;&#039;...&amp;lt;/ref&amp;gt;&lt;br /&gt;
| ext3&lt;br /&gt;
| /var/appslog&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | home&lt;br /&gt;
| 1GiB&amp;lt;ref name=&amp;quot;home&amp;quot;&amp;gt;Note that this heavily depends on the purpose of the machine; if it is not to house any users, then (almost) no space is needed for /home. But on the other hand if e.g. a virtual user is to be used for keeping mailstores, or other service users need home space, then /home needs to be big enough for that.&amp;lt;/ref&amp;gt;&lt;br /&gt;
| 512MiB&amp;lt;ref name=&amp;quot;home&amp;quot;/&amp;gt;&lt;br /&gt;
| ext3&lt;br /&gt;
| /home&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | usr&lt;br /&gt;
| 3GiB&lt;br /&gt;
| 3GiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /usr&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | tmp&lt;br /&gt;
| 1GiB&lt;br /&gt;
| 512MiB&lt;br /&gt;
| ext3&lt;br /&gt;
| /tmp&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;background:lightgrey&amp;quot; | opt&lt;br /&gt;
| 1GiB&lt;br /&gt;
| -&lt;br /&gt;
| ext3&lt;br /&gt;
| /opt&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:right&amp;quot;| Total&lt;br /&gt;
! 18.1GiB&lt;br /&gt;
! 6.9GiB&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
As you can see, the partition table works as follows: we assume that we wind up with 3 partitions, either on three separate software RAID arrays (&#039;&#039;md0&#039;&#039; through &#039;&#039;md2&#039;&#039;) or on one single hardware RAID array (in which case the 2nd column &#039;&#039;MD&#039;&#039; does not apply). The size of the partitions depends on your machine&#039;s make: for standard physical machines the 5th column does sensible suggestions, even though you could choose to have different sizes and of course different divisions altogether. If your machine happens to be a virtual one, running inside a [http://www.vmware.com/products/vsphere VMware Server] or something alike, then you might want to start out with more modest partitions. The same holds for small servers that must run off Flash drives.&lt;br /&gt;
&lt;br /&gt;
Anyways, we&#039;re now at the Debian installation screen that lets us partition our disks. We&#039;re &#039;&#039;not&#039;&#039; going to use any of the &amp;quot;guided&amp;quot; partitioning options, we go for &amp;quot;manual&amp;quot;. Choosing that brings us to a screen showing all drives that the installation routine has detected, and all partitions on those drives that the installer can &amp;quot;see&amp;quot;. We&#039;re going to do some assuming here once more: let&#039;s assume the drive(s) on which you want to install are visible, and are empty (containing no other partitions).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Software RAID partitioning===&lt;br /&gt;
If you&#039;re to use software RAID, you now have to select the free space on the first drive, press &amp;amp;lt;enter&amp;amp;gt;, and then tell what you want to do with the free space: create a new partition, tell which size you want it to be (see table above), give the type of partition (primary), and give where on the disk it&#039;ll sit (the beginning). Next, a screen comes up that details how the partition you&#039;re requesting will be created. Here we make some changes: under &amp;quot;use as&amp;quot; we&#039;re going to select &amp;quot;physical volume for RAID&amp;quot;. This clears all the other options in this screen, except for the &amp;quot;bootable&amp;quot; flag, which must be &amp;quot;on&amp;quot; for the first partition that we&#039;ll mount as &#039;&#039;/boot&#039;&#039;. Now select &amp;quot;Done setting up the partition&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Next, go to the free space on the second disk, and do &#039;&#039;exactly&#039;&#039; the same, to create an identical physical volume for RAID - if it&#039;s the first partition, select the &amp;quot;bootable&amp;quot; flag as well (we&#039;ll want to be able to boot from this second disk if the first disk fails, right?).&lt;br /&gt;
&lt;br /&gt;
Then go back to the rest of the free space on the first disk, make the second physical volume for RAID, duplicate it on the second disk. Then, go back to the rest of the free space on the first disk, make the third physical volume for RAID, and again duplicate it on the second disk.&lt;br /&gt;
&lt;br /&gt;
If you now go back to the &amp;quot;partition disks&amp;quot; overview, you&#039;ll see all the partitions you&#039;ve specified listed on their respective disks. But at the top an extra option has appeared, called &amp;quot;configure software RAID&amp;quot;. When you now select this option, the installer will ask if it may write the changes you&#039;ve made to disk. This actually creates the partition tables on the disks.&lt;br /&gt;
&lt;br /&gt;
Now you can create RAID devices. The RAID levels that Debian 6.0 offer are 0 (striping), 1 (mirroring), 5 (distributed redundancy), 6 (double distributed redundancy) ant 10 (striped mirrors). For your operating system disk pair, level 1 is the only sane choice.&lt;br /&gt;
&lt;br /&gt;
When selecting RAID 1, the installer asks how many active devices to use (2), how many spares (0), and then offers a selection screen where you can mark all members of the array. Select the first partition of both disks (presumably &#039;&#039;/dev/sda1&#039;&#039; and &#039;&#039;/dev/sdb1&#039;&#039;) which should correspond to the 100MiB partitions you&#039;ve created. Then create the other MD devices. Finally, choose &amp;amp;lt;finish&amp;amp;gt;. You&#039;ll drop back to the partitioner, but now the three created devices are available in the partitioner as &amp;quot;RAID1 device #0&amp;quot; etc.&lt;br /&gt;
&lt;br /&gt;
===Hardware RAID partitioning===&lt;br /&gt;
Now, if you have hardware RAID, then on your first (boot) disk just make 3 partitions, in the following manner:&lt;br /&gt;
&lt;br /&gt;
Select the free space on the intended boot disk, press &amp;amp;lt;enter&amp;amp;gt;, select &amp;quot;create a new partition&amp;quot;, and fill out the desired size (100MB). Type is primary, location is beginning of the disk, and in the details of the partition, we only need to change the Mount point to &amp;quot;/boot&amp;quot;, and set the Bootable flag to &amp;quot;On&amp;quot;. Then we&#039;re &amp;quot;Done setting up this partition&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The second partition is made the same way, but the desired size is 3GB, the Mount point is &amp;quot;/&amp;quot;, and the Bootable flag remains off. Again, we&#039;re &amp;quot;Done setting up this partition&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The third partition is again a primary partition, it takes up the entire rest of the disk, but the type is not ext3, but &amp;quot;physical volume for LVM&amp;quot;. Again, we&#039;re &amp;quot;Done setting up this partition&amp;quot;. But now from the main partitioner screen, we can access &amp;quot;Configure the Logical Volume Manager&amp;quot;. The installer asks if it can write out the choices made to the disk, and then enters the LVM setup screen, which begins with a summary explaining that you have one Free Physical Volume, and nothing more.&lt;br /&gt;
&lt;br /&gt;
==Logical Volume creation==&lt;br /&gt;
We now create a Volume Group (VG), which (in accordance to our partitioning standard) we&#039;ll call &amp;quot;system&amp;quot;. In this VG, we&#039;ll add all Physical Volumes (being the one partition we&#039;ve designated so in the previous step) using the space bar. To this end, in the volume group creation dialogue, we select that partition (&#039;&#039;/dev/md2&#039;&#039;). Note that all other selection choices are either unusable (unusable free space) or assigned to other purposes (/boot and /).&lt;br /&gt;
&lt;br /&gt;
Now we repeat the following process seven times:&lt;br /&gt;
* select &amp;quot;Create Logical Volume&amp;quot;&lt;br /&gt;
* select Volume Group &amp;quot;System&amp;quot;&lt;br /&gt;
* give the LV Name (from the table, e.g. swap, var etc)&lt;br /&gt;
* give the LV size (from the table, e.g. 1GB for swap etc)&lt;br /&gt;
&lt;br /&gt;
After this, we can select &amp;quot;Finish&amp;quot;, the partitioner creates the seven LVs, and we&#039;re back at the partitioner screen, where there are now 7 extra &amp;quot;disks&amp;quot;, with names such as &#039;&#039;LVM VG system, LV appslog - 3.0GB Linux device mapper (linear)&#039;&#039;. Each of these &amp;quot;disks&amp;quot; has one block of empty space, which we now assign: seven times we repeat the following process:&lt;br /&gt;
* select the unassigned chunk of empty space of an LV (e.g. &#039;&#039;appslog&#039;&#039;) and press &amp;amp;lt;enter&amp;amp;gt;;&lt;br /&gt;
* Change &amp;quot;Use as: do not use&amp;quot; into the desired filesystem (ext3 - only the LV &amp;quot;swap&amp;quot; gets as filesystem type &amp;quot;swap area&amp;quot;);&lt;br /&gt;
* Change the mount point from &amp;quot;none&amp;quot; to the one corresponding with the name of the LV (note: the swap LV has no mountpoint; the appslog mountpoint must be entered manually as &amp;quot;/var/appslog&amp;quot; and varlog as &amp;quot;/var/log&amp;quot;);&lt;br /&gt;
* If so desired, a label can be assigned to the partition (we usually don&#039;t);&lt;br /&gt;
* select &amp;quot;Done setting up the partition&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Note that sometimes, after creating and assigning the logical volumes, the installer has forgotten to mount the md0 and md1 partitions as /boot and /. In that case you&#039;ll have to reassign these partitions to these points in the filesystem.&lt;br /&gt;
&lt;br /&gt;
Once all this is done, we can look over the configuration once more, and then select &amp;quot;Finish partitioning and write changes to disk&amp;quot;. A summary configuration screen will show, and we&#039;ll affirm with &amp;quot;yes&amp;quot; that these partitions can indeed be formatted. After some formatting screens flashing by (unless your partitions are particularly big, your system is particularly slow, or something goes wrong) the installation procedure continues.&lt;br /&gt;
&lt;br /&gt;
==Base system setup==&lt;br /&gt;
Now the Debian installer loads a base system. It will scan your installation CD/DVD, and ask if it should scan more CD/DVDs. We&#039;re going with &amp;quot;no&amp;quot; here. Then it will ask you how it can contact the Debian archives, in the dialogue &amp;quot;configure the package manager&amp;quot;. For the NetInstall version of Debian, this is as good as mandatory. So here, we say &amp;quot;yes, use a Network Mirror&amp;quot;, and in the following list select the country in which we are (in our case: the Netherlands), so the installer can present us with a number of network mirrors &amp;quot;close by&amp;quot;. We select ftp.nl.debian.org. Next screen: should you be behind a proxy server, then it&#039;s possible to specify that here. And then the test: the system will say &amp;quot;scanning the mirror...&amp;quot; and try to contact the specified mirror. If it does not succeed, then there is either a network problem, a problem with this box&#039;s network card, or you&#039;ve not specified the mirror or proxy correctly - so fix it. You&#039;ll know the network mirror has successfully been contacted when it&#039;s saying &amp;quot;Retrieving file 1 of 5&amp;quot;. A number of files are retrieved, and the base system is set up. Somewhere early in this setup, the next dialogue appears - currently &amp;quot;configuring popularity-contest&amp;quot;. Answer this question as you please.&lt;br /&gt;
And then one of the last &amp;quot;big&amp;quot; questions: Software Selection. In this dialogue, you can easily select bundles of software to be installed. The choices are currently:&lt;br /&gt;
* Graphical desktop environment&lt;br /&gt;
* Web server&lt;br /&gt;
* Print server&lt;br /&gt;
* DNS server&lt;br /&gt;
* File server&lt;br /&gt;
* Mail server&lt;br /&gt;
* SQL database&lt;br /&gt;
* SSH server&lt;br /&gt;
* Laptop&lt;br /&gt;
* Standard system  utilities (selected by default)&lt;br /&gt;
We have to make a little confession here: we&#039;ve never before used this option in the installer. In fact, we even deselect the Standard System, so as to minimize the number of software packages that the base installation of our server contains. This makes it more work to manually add packages later, but we feel it gives us more control and understanding of our systems. So if you&#039;re like us: deselect the &amp;quot;Standard system utilities&amp;quot; entry, and select Continue.&lt;br /&gt;
&lt;br /&gt;
The next dialogue handles the installation of the [http://www.gnu.org/software/grub/ &#039;&#039;grub&#039;&#039; bootloader]. Unless your disks weren&#039;t empty and you&#039;re attempting to make this system multiboot, you&#039;ll most likely get a question if you&#039;ll allow the installer to install &#039;&#039;grub&#039;&#039; into the boot sector of the first hard disk. We&#039;ll confirm with &amp;quot;Yes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
After the installation of grub is completed, the CD-ROM is ejected, and the system is ready to reboot into Debian Squeeze. Remove the CD and select &amp;quot;Continue&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Finishing up the installation==&lt;br /&gt;
The system should reboot into Debian. This means you should see the following boot sequence:&lt;br /&gt;
* your machine&#039;s standard POST messages&lt;br /&gt;
* briefly a &#039;&#039;&#039;welcome to GRUB&#039;&#039;&#039; message&lt;br /&gt;
* then, a blue grub menu on a black screen, with two entries:&lt;br /&gt;
** Debian GNU/Linux, with Linux 2.6.32-5-686&lt;br /&gt;
** Debian GNU/Linux, with Linux 2.6.32-5-686 (recovery mode)&lt;br /&gt;
* then, after a default (short!) time-out, the first grub option will go into effect, and the Linux kernel is started. Lots of cryptic messages in grey-on-black will scroll by, until the last few lines read:&lt;br /&gt;
 Debian GNU/Linux 6.0 easton2 tty1&lt;br /&gt;
 easton2 login: &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
If your system does not reach this login, and/or some horrible error messages appear anywhere in this boot sequence, then you&#039;ve got some extra work ahead. For now we&#039;ll assume you&#039;ve reached the login prompt without problem.&lt;br /&gt;
&lt;br /&gt;
Log in as the principal user (try to avoid logging in as root! That&#039;s BAD practice!). Once logged in, save a copy of the boot messages using &#039;&#039;sudo dmesg &amp;gt; boot.txt&#039;&#039; or whatever you like. Then look through the boot messages, e.g. with &#039;&#039;vi -R boot.txt&#039;&#039;. Furthermore, [[APT_and_aptitude | use Aptitude]] to make sure &#039;&#039;all&#039;&#039; your software is updated to the latest version.&lt;br /&gt;
&lt;br /&gt;
Done! Your base system is ready. You probably now want to [[essential system software | install essential software]], [[roll your own kernel]] and [[connect your server to the Internet]]. Furthermore, you might want to create a couple of [[aliases in every profile]] so that your favourite commands are always available.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3069</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3069"/>
		<updated>2014-10-26T20:32:47Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: typos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using SSH keys for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSH keys to the mix.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key file, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a sidenote, if you need the private key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:qw&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next session).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3068</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3068"/>
		<updated>2014-10-26T20:29:55Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: ssh server config&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using certificates for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSL keys to the mix.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key file, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a sidenote, if you need the private key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:qw&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;br /&gt;
&lt;br /&gt;
To ensure that the SSH server accepts SSH keys, add the following to &#039;&#039;/etc/ssh/sshd_config&#039;&#039;, or at least confirm the lines are already there:&lt;br /&gt;
 RSAAuthentication yes&lt;br /&gt;
 PubkeyAuthentication yes&lt;br /&gt;
 AuthorizedKeysFile     %h/.ssh/authorized_keys&lt;br /&gt;
If you&#039;ve changed any of these settings, restart the SSH server to ensure they&#039;re implemented. Then test if you can log in to the server with your SSH key (see next session).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve ensured you can log into the server using only the key and it&#039;s associated passphrase, you may wish to disable password-based login. To configure the SSH server to &#039;&#039;not&#039;&#039; accept passwords any more, add the following (or confirm it&#039;s already set):&lt;br /&gt;
 ChallengeResponseAuthentication no&lt;br /&gt;
 PasswordAuthentication no&lt;br /&gt;
Again, restart the server if you&#039;ve changed these settings. BEWARE! If you haven&#039;t properly tested logging in with a key, and you disable password-based login, then you&#039;ve shut yourself out. Only access to the console can then restore your access...&lt;br /&gt;
&lt;br /&gt;
===Configuring PuTTy to use the SSH key===&lt;br /&gt;
You&#039;ve added your public key to the server, now add your private key to your PuTTy session information.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3067</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3067"/>
		<updated>2014-10-26T20:06:57Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: intermediate save&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using certificates for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSL keys to the mix.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTyGen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer, but takes longer to generate);&lt;br /&gt;
* Now click the Generate button. PuTTyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. (Really, only leave out the passphrase if you would like to use this particular key pair for automated processes!)&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuTTyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the key on the server===&lt;br /&gt;
To put the key on the server, we need to use not the public key file, as the file itself is in a format that OpenSSH doesn&#039;t recognize. So we can again open PuTTyGen, click &#039;&#039;load&#039;&#039; to load an existing private key file, and select the private key from the safe folder used below. After entering the passphrase (twice) we see the same information as before (see pic above). From the PuTTyGen interface, we select &amp;amp; copy to clipboard the information in the top window, something like&lt;br /&gt;
 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEAjisviHZ19eU0F5BtN+F32tcjO72Ne&lt;br /&gt;
 82Br24XS5cQASuYt8EZXBP1bdh0JFX7KvJIBMzH6KXo0gZQv/UtX4q+9jV9xgCgWq&lt;br /&gt;
 IAM+WKEVexAkR1RjFc8Bf8pPK62eNsis959+XD0IuuH7Ge/JKTy6ScxU+nyIfBJr/&lt;br /&gt;
 a894TNPwdCEAbnBdU6WX/Q7g3P7xVaMu2g5okLRkO1tt7wIlt0zrOx86hMvesmIwX&lt;br /&gt;
 CfZ8qJtp8frmpoxbbCn9akgDPRtmMUEJDDkgrW6oyyMCtCgH0iTEZf3RYq4aOdXAI&lt;br /&gt;
 bJE9Yu402BPmyZCSDBrqwYfEWn0FgtEsjTlc7TTnUq+X35ndCpwE+g4AV3Fle7e18&lt;br /&gt;
 eNyqvb3ng2+nSj4uNj2fFqlfNrJXfZGVELmk7xnVH1ypP6WamFHxG81wAqkGnBA2q&lt;br /&gt;
 W1ItvJxZ3L3mfHX5LKUxMMXbw5hElXtVQI+ZiDPjFqCIqPXagYzIsh/XzKbXoxZnR&lt;br /&gt;
 abcc14wGdPM+3TuAgyARoVuYyMb6iJz7SMrf1OAvMD6P7AcY5l7PeFG88ABJc67kS&lt;br /&gt;
 fPAyZRrK7uHllh2P3B3lEzIWrXYvKqjMoOOQj0uAhHtmFVtDvu/bHgJ2BWrTYq9AI&lt;br /&gt;
 g7AY59QnzK0LO8BxAoTSTKuUNpj+9WP7FUNL60nejm6A68PXQRddVrAZ2SYUuTUB+&lt;br /&gt;
 /pU0= Joe Sixpack&lt;br /&gt;
Note that on pasting this information in e.g. Notepad, then it should be a &#039;&#039;single&#039;&#039; line of information.&lt;br /&gt;
&lt;br /&gt;
On a sidenote, if you need the private key in an &#039;&#039;OpenSSH&#039;&#039; or &#039;&#039;ssh.com&#039;&#039; compatible form, you can use the Conversions tab on the toolbar.&lt;br /&gt;
&lt;br /&gt;
Next, we open a PuTTy SSH session to the server, change directory to the user&#039;s home directory (e.g. &#039;&#039;/home/jsixpack&#039;&#039;), and in this home directory go into the &#039;&#039;.ssh&#039;&#039; directory. Inside that directory there should be a file &#039;&#039;authorized_keys&#039;&#039;. If it&#039;s not there, create it with the user as owner and read/write for the user only. In the example of user &#039;&#039;jsixpack&#039;&#039;:&lt;br /&gt;
 cd /home/jsixpack/.ssh&lt;br /&gt;
 touch authorized_keys&lt;br /&gt;
 chmod 600 authorized_keys&lt;br /&gt;
Then open this file with [[Vim|vi]], and copy the public key in there. Again, it should be a single line, beginning with &#039;&#039;ssh-rsa AAAA&#039;&#039; and ending with the key comment. Save with &#039;&#039;:qw&#039;&#039; and the key is stored! &lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=File:Puttygen.png&amp;diff=3066</id>
		<title>File:Puttygen.png</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=File:Puttygen.png&amp;diff=3066"/>
		<updated>2014-10-26T19:59:12Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: Saruman! uploaded a new version of &amp;amp;quot;File:Puttygen.png&amp;amp;quot;: correct example username&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PuttyGen interface&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3065</id>
		<title>OpenSSH server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=OpenSSH_server&amp;diff=3065"/>
		<updated>2014-10-26T10:45:38Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: start ssh key section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==OpenSSH Server==&lt;br /&gt;
&lt;br /&gt;
This package is essential when you want to be able to (safely) administer your server from another place than the console.&lt;br /&gt;
&lt;br /&gt;
To install: simpy use &#039;&#039;sudo aptitude install openssh-server&#039;&#039;. This will install the OpenSSH server, plus the OpenSSH client. Since the SSL vulnerbility of may &#039;08, also the ssh-blacklist package is downloaded.&lt;br /&gt;
&lt;br /&gt;
After installing, we need to make the following changes to the default settings in file &#039;&#039;/etc/ssh/sshd-config&#039;&#039;:&lt;br /&gt;
* line &#039;&#039;PermitRootLogin yes&#039;&#039; should be set to &#039;&#039;no&#039;&#039;, so that user &#039;&#039;root&#039;&#039; CANNOT log in over SSH! ([http://www.debian-administration.org/articles/573 big security gap!]).&lt;br /&gt;
* add a line &#039;&#039;AllowGroups wheel&#039;&#039;; adding this ensures that NOBODY can log in over SSH unless you specifically assigned them to the &#039;&#039;wheel&#039;&#039; group, reducing the attack surface of your SSH user. Should you need more than one group (e.g. you want to add the group &amp;quot;ldapwheel&amp;quot;), then add the groups separated by spaces: &#039;&#039;AllowGroups wheel ldapwheel&#039;&#039;.&lt;br /&gt;
* Change your banner by editing the [[MOTD file]].&lt;br /&gt;
&lt;br /&gt;
Next, make sure the &#039;&#039;wheel&#039;&#039; group exist, and add all users to it that are allowed ssh-access:&lt;br /&gt;
 groupadd -g 117 wheel&lt;br /&gt;
 usermod -a -G wheel jan&lt;br /&gt;
In the groupadd line, the groupID is explicitly set to 117, but this really is optional. In the usermod line, be sure to use the &#039;&#039;-a&#039;&#039; so that your user gets the ssh-users group added, instead of replacing all supplementary groups with this one ssh-users.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve added a group that exists in your LDAP server, make sure that those LDAP users are member of that group that you want to give SSH access. This is ofcourse managed from your LDAP management console (be it the commandline &#039;&#039;ldapmodify&#039;&#039; or a graphic tool like [[Filling_an_OpenLDAP_database#Adding_a_user_with_LAM | LDAP Account Manager]]&lt;br /&gt;
&lt;br /&gt;
When all this is changed, the service should be restarted with &#039;&#039;sudo /etc/init.d/ssh restart&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
One of the nice things of a correctly configured SSH server, is the ability to use [[scp]] to copy files between machines.&lt;br /&gt;
&lt;br /&gt;
== Changing RSA keys ==&lt;br /&gt;
Occasionally you&#039;ll find the RSA key of one of your machines has changed. This may have a number of reasons, a.o. a reinstall or migration of said machine. In any case, when you try to SSH to the machine you get a message like this:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh insomnia@easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&lt;br /&gt;
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&lt;br /&gt;
 Someone could be eavesdropping on you right now (man-in-the-middle attack)!&lt;br /&gt;
 It is also possible that the RSA host key has just been changed.&lt;br /&gt;
 The fingerprint for the RSA key sent by the remote host is&lt;br /&gt;
 f7:1a:5a:11:ca:20:99:fa:db:1b:b8:75:8e:e5:f1:12.&lt;br /&gt;
 Please contact your system administrator.&lt;br /&gt;
 Add correct host key in /home/sixpacjo/.ssh/known_hosts to get rid of this message.&lt;br /&gt;
 Offending key in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
 RSA host key for easton.saruman.biz has changed and you have requested strict checking.&lt;br /&gt;
 Host key verification failed. &lt;br /&gt;
 localhost:~# _&lt;br /&gt;
When you get this message it is not possible to connect to the machine mentioned, until you&#039;ve solved the problem of the RSA key. There are multiple ways to correct the key, but the simplest method seems to be to simply remove the offending key with &#039;&#039;ssh-keygen&#039;&#039;. Note that Debian &amp;quot;Lenny&amp;quot; stores the RSA key in &#039;&#039;two&#039;&#039; places: one for the host name, one for the IP number. To prevent annoying messages like this:&lt;br /&gt;
 Warning: the RSA host key for &#039;easton.saruman.biz&#039; differs from the key for the IP address &#039;192.168.67.5&#039;&lt;br /&gt;
 Offending key for IP in /home/sixpacjo/.ssh/known_hosts:4&lt;br /&gt;
you should remove the RSA key for the IP number as well. This you do with the following two commands:&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R easton.saruman.biz&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# &#039;&#039;&#039;ssh-keygen -R 192.168.67.5&#039;&#039;&#039;&lt;br /&gt;
 /home/sixpacjo/.ssh/known_hosts updated.&lt;br /&gt;
 Original contents retained as /home/sixpacjo/.ssh/known_hosts.old&lt;br /&gt;
 localhost:~# _&lt;br /&gt;
After deleting the &amp;quot;offending RSA keys&amp;quot; like this, you can SSH to the box in question, and your SSH client will save the (new) RSA key for you in your &#039;&#039;known_hosts&#039;&#039; file.&lt;br /&gt;
&lt;br /&gt;
==Using certificates for SSH login==&lt;br /&gt;
If your server is open to the Internet, passwords alone may not be safe enough. Plenty of malicious folks will try to brute-force attack your SSH server. Of course you&#039;ve disabled root login (right? RIGHT?!?) but still... all that attacking clutters your logs, and maybe one day one of your SSH user passwords turns out too weak. That&#039;s why it&#039;s a good idea to add SSL keys to the mix.&lt;br /&gt;
&lt;br /&gt;
===Generating an SSH key===&lt;br /&gt;
You can generate an SSH key from Linux itself (see [https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 DigitalOcean], but in this article we&#039;ll use [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTy], because PuTTy/WinSCP is the go-to tool set for Linux administration from a Windows workstation, and PuTTy&#039;s [http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/key-formats-natively.html proprietary key management] provides some nifty tricks for key management.&lt;br /&gt;
(based on [https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps DigitalOcean howto])&lt;br /&gt;
&lt;br /&gt;
First we start the PuTTYgen utility, by double-clicking on its .exe file. &lt;br /&gt;
* At the bottom of the interface, for Type of key to generate, select SSH-2 RSA;&lt;br /&gt;
* In the Number of bits in a generated key field, specify either 2048 or 4096 (the latter is safer);&lt;br /&gt;
* Now click the Generate button. PuttyGen needs some entropy, so move your mouse pointer around in the blank area of the Key section for a while until the progress bar is full - a private/ public key pair will then be generated;&lt;br /&gt;
* In the Key comment field, enter your name (or any other comment you&#039;d like), to help you identify this key pair. This is particularly useful in the event you end up creating more than one key pair;&lt;br /&gt;
* A passphrase is optional but recommended: Type &amp;amp; re-type it in the Key passphrase fields. Really, only leave out the passphrase if you would like to use this particular key pair for automated processes.&lt;br /&gt;
The above actions should look a bit like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Puttygen.png|PuttyGen interface]]&lt;br /&gt;
&lt;br /&gt;
* Now click the Save public key button &amp;amp; choose whatever filename you&#039;d like, saving it in a &amp;quot;safe&amp;quot; folder. I&#039;d recommend a filename that corresponds to the Key comment field content;&lt;br /&gt;
* Then click the Save private key button &amp;amp; choose whatever filename you&#039;d like (you can save it in the same location as the public key, but it should be a location that only you can access and that you will NOT lose!). Keep the file extension to &#039;&#039;&#039;.ppk&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Putting the key on the server===&lt;br /&gt;
&lt;br /&gt;
===Configuring the SSH server===&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=File:Puttygen.png&amp;diff=3064</id>
		<title>File:Puttygen.png</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=File:Puttygen.png&amp;diff=3064"/>
		<updated>2014-10-26T10:30:21Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: PuttyGen interface&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PuttyGen interface&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3063</id>
		<title>Your own ownCloud</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3063"/>
		<updated>2014-02-10T14:20:21Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: fixed ToC&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;ownCloud&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
In this day and age where many people are more and more dependant on information, cloud technology offers a way to unlock your information to you, wherever you are, on most any device. However, there&#039;s no telling what the cloud companies that you entrust with your information will do with that info - let alone nosy intelligence agencies from various countries around the world. My privacy [https://chronicle.com/article/Why-Privacy-Matters-Even-if/127461/ matters to me]!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[http://owncloud.org/ ownCloud]&#039;&#039;&#039; is a free and open source alternatives for many cloud offerings such as Google Drive and DropBox, as it gives you the ability to share and sync files from your own server, but it does [http://owncloud.org/features/ much more] - added bonus, I say...&lt;br /&gt;
&lt;br /&gt;
___TOC___&lt;br /&gt;
==Introduction==&lt;br /&gt;
ownCloud broadly comes in two flavours: the open source, free &amp;quot;community edition&amp;quot; and the open source, paid &amp;quot;enterprise edition&amp;quot;. We&#039;re going to install the community edition here. The goal will be to have a way to share files between groups of people, most of which will have an account on our server.&lt;br /&gt;
&lt;br /&gt;
==Installing ownCloud==&lt;br /&gt;
In the following we&#039;re going to install ownCloud manually, that is to say we&#039;re not going to use any Linux package manager such as Debian&#039;s [https://wiki.debian.org/Apt apt] or Red Hat/CentOS&#039;s [https://access.redhat.com/site/solutions/9934 yum], but we&#039;re going to manually put the necessary files on the server. This has the advantage of being able to use the very latest &amp;amp; greatest version of ownCloud, but the disadvantage requiring us to do the heavy lifting, install-wise as well as update-wise. However, as we&#039;ll see below, a manual installation takes relatively little effort.&lt;br /&gt;
&lt;br /&gt;
===Preparing your server===&lt;br /&gt;
First off we have to ensure that our server complies with ownCloud&#039;s requirements, as shown in the [http://doc.owncloud.org/server/6.0/admin_manual/installation/installation_source.html administrator manual]. This means we&#039;ll require a working LAMP server with a sufficient recent version of PHP, MySQL and Apache. If we want to secure our ownCloud communications using SSL, we also need to have a good SSL certificate (preferably not a self-signed one as many applications choke on that signature) and have set up our Apache server to correctly use it. Furthermore, ownCloud needs the Apache module mod-rewrite; usually one can enable it with a command such as &#039;&#039;a2enmod rewrite&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Getting ownCloud files on your server===&lt;br /&gt;
Now we&#039;ll choose a directory in which the ownCloud files can live; as it&#039;s a  manual package, the Linux Standards Base ([http://www.linuxfoundation.org/collaborate/workgroups/lsb LSB]) suggests it goes into &#039;&#039;/opt&#039;&#039;. We thus create the directory &#039;&#039;/opt/owncloud&#039;&#039;. Next up we download the ownCloud &#039;&#039;tar.bz2&#039;&#039; file from the [http://owncloud.org/install/ ownCloud download page] to a temporary directory and extract it; this could look like&lt;br /&gt;
 cd /tmp&lt;br /&gt;
 wget http://download.owncloud.org/community/owncloud-6.0.1.tar.bz2&lt;br /&gt;
 tar -xjf owncloud-6.0.1.tar.bz2&lt;br /&gt;
Note that the extraction causes the tree of ownCloud files to appear in a directory called &#039;&#039;owncloud&#039;&#039;. Strictly speaking you could extract the file directly in /opt without first creating an &#039;&#039;owncloud&#039;&#039; directory by hand. However I like to keep an eye on processes like this. We can now move all the files from the tar into the prepared directory with a command such as&lt;br /&gt;
 cp -pR /tmp/owncloud/* /opt/owncloud&lt;br /&gt;
Here please note that all files in the tar file are owned by a user with UID and GID 65534, corresponding with &#039;&#039;nobody:nogroup&#039;&#039;. If your server or webserver setup require a different user/group, you should use &#039;&#039;chown&#039;&#039; to set this.&lt;br /&gt;
&lt;br /&gt;
===Publishing ownCloud in Apache2===&lt;br /&gt;
As we would like all files pertaining to the configuration of our server to live under &#039;&#039;/etc&#039;&#039;, we create a directory &#039;&#039;/etc/owncloud&#039;&#039;. Now, in this directory we&#039;ll create a file named &#039;&#039;apache.conf&#039;&#039; containing&lt;br /&gt;
 Alias /cloud /opt/owncloud&lt;br /&gt;
 &amp;lt;Directory /opt/owncloud&amp;gt;&lt;br /&gt;
     Options Indexes FollowSymLinks MultiViews&lt;br /&gt;
     AllowOverride All&lt;br /&gt;
     Order allow,deny&lt;br /&gt;
     allow from all&lt;br /&gt;
 &amp;lt;/Directory&amp;gt;&lt;br /&gt;
Publishing the ownCloud instance is now as easy as including this file in the relevant Apache (SSL) site configuration file. Under Debian, this means selecting the right file under &#039;&#039;/etc/apache2/sites-available/&#039;&#039; and insert the line&lt;br /&gt;
 Include /etc/owncloud/apache.conf&lt;br /&gt;
If you now reload Apache with a command such as &#039;&#039;service apache2 reload&#039;&#039;, you&#039;ll be able to surf to the URL of the pertaining site (e.g. https://www.saruman.biz/owncloud) and verify that the unconfigured owncloud instance is now accessible.&lt;br /&gt;
&lt;br /&gt;
==Configuring ownCloud==&lt;br /&gt;
===Initial setup===&lt;br /&gt;
We&#039;ll need &#039;&#039;&#039;a data directory&#039;&#039;&#039; for ownCloud. My recommendation is something like &#039;&#039;/data/owncloud&#039;&#039;, and since the web server is required to manipulate files in this directory, we&#039;ll make it owned by Debian&#039;s webserver user/group &#039;&#039;www-data:www-data&#039;&#039; (under other distributions, make sure to use the corresponding user/group). For this directory to be used by ownCloud, we&#039;ll symlink to it from &#039;&#039;/opt/owncloud&#039;&#039; with command:&lt;br /&gt;
 ln -s /data/owncloud /opt/owncloud/data&lt;br /&gt;
&lt;br /&gt;
We&#039;ll also need &#039;&#039;&#039;a database&#039;&#039;&#039; for ownCloud. To create one, we can start the MySQL client (&#039;&#039;mysql -u root -p&#039;&#039; and then the password) and create a database plus database user using&lt;br /&gt;
 mysql&amp;gt; create database owncloud;&lt;br /&gt;
 mysql&amp;gt; create user &#039;ownclouduser&#039;@&#039;localhost&#039; identified by &#039;&amp;lt;password1&amp;gt;&#039;;&lt;br /&gt;
 mysql&amp;gt; grant all on owncloud.* to &#039;ownclouduser&#039;@&#039;localhost&#039;;&lt;br /&gt;
&lt;br /&gt;
Now we can surf to the ownCloud instance page, and we&#039;ll find the startscreen asking for setup details. Provided the following details:&lt;br /&gt;
* Admin account: &#039;&#039;&#039;owncloudadmin/&amp;lt;password2&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
* Data folder: &#039;&#039;&#039;/opt/owncloud/data&#039;&#039;&#039;&lt;br /&gt;
* Database user: &#039;&#039;&#039;ownclouduser/&amp;lt;password1&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
* Database name: &#039;&#039;&#039;owncloud&#039;&#039;&#039;&lt;br /&gt;
* Database host: &#039;&#039;&#039;localhost&#039;&#039;&#039;&lt;br /&gt;
Once we&#039;ve finished the installation wizard, we&#039;ll be able to log in to ownCloud using the admin account (here &#039;&#039;owncloudadmin&#039;&#039;) and the corresponding password.&lt;br /&gt;
&lt;br /&gt;
If logging in works, then the following action will complete the configuration according to the LSB. We&#039;ll move the file &#039;&#039;/opt/owncloud/config/config.php&#039;&#039; that the installation wizard has created to our directory &#039;&#039;/etc/owncloud&#039;&#039; (if you like, you can also move the example configuration file &#039;&#039;config.sample.php&#039;&#039; for future reference). Then we symlink to it using&lt;br /&gt;
 ln -s /etc/owncloud/config.php /opt/owncloud/config/config.php&lt;br /&gt;
&lt;br /&gt;
===Using OpenLDAP as a backend===&lt;br /&gt;
===Theming ownCloud===&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3062</id>
		<title>Your own ownCloud</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3062"/>
		<updated>2014-02-10T14:19:30Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* Installing ownCloud */  fleshed out&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;ownCloud&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
In this day and age where many people are more and more dependant on information, cloud technology offers a way to unlock your information to you, wherever you are, on most any device. However, there&#039;s no telling what the cloud companies that you entrust with your information will do with that info - let alone nosy intelligence agencies from various countries around the world. My privacy [https://chronicle.com/article/Why-Privacy-Matters-Even-if/127461/ matters to me]!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[http://owncloud.org/ ownCloud]&#039;&#039;&#039; is a free and open source alternatives for many cloud offerings such as Google Drive and DropBox, as it gives you the ability to share and sync files from your own server, but it does [http://owncloud.org/features/ much more] - added bonus, I say...&lt;br /&gt;
&lt;br /&gt;
___TOC___&lt;br /&gt;
==Introduction==&lt;br /&gt;
ownCloud broadly comes in two flavours: the open source, free &amp;quot;community edition&amp;quot; and the open source, paid &amp;quot;enterprise edition&amp;quot;. We&#039;re going to install the community edition here. The goal will be to have a way to share files between groups of people, most of which will have an account on our server.&lt;br /&gt;
&lt;br /&gt;
==Installing ownCloud==&lt;br /&gt;
In the following we&#039;re going to install ownCloud manually, that is to say we&#039;re not going to use any Linux package manager such as Debian&#039;s [https://wiki.debian.org/Apt apt] or Red Hat/CentOS&#039;s [https://access.redhat.com/site/solutions/9934 yum], but we&#039;re going to manually put the necessary files on the server. This has the advantage of being able to use the very latest &amp;amp; greatest version of ownCloud, but the disadvantage requiring us to do the heavy lifting, install-wise as well as update-wise. However, as we&#039;ll see below, a manual installation takes relatively little effort.&lt;br /&gt;
&lt;br /&gt;
===Preparing your server===&lt;br /&gt;
First off we have to ensure that our server complies with ownCloud&#039;s requirements, as shown in the [http://doc.owncloud.org/server/6.0/admin_manual/installation/installation_source.html administrator manual]. This means we&#039;ll require a working LAMP server with a sufficient recent version of PHP, MySQL and Apache. If we want to secure our ownCloud communications using SSL, we also need to have a good SSL certificate (preferably not a self-signed one as many applications choke on that signature) and have set up our Apache server to correctly use it. Furthermore, ownCloud needs the Apache module mod-rewrite; usually one can enable it with a command such as &#039;&#039;a2enmod rewrite&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Getting ownCloud files on your server===&lt;br /&gt;
Now we&#039;ll choose a directory in which the ownCloud files can live; as it&#039;s a  manual package, the Linux Standards Base ([http://www.linuxfoundation.org/collaborate/workgroups/lsb LSB]) suggests it goes into &#039;&#039;/opt&#039;&#039;. We thus create the directory &#039;&#039;/opt/owncloud&#039;&#039;. Next up we download the ownCloud &#039;&#039;tar.bz2&#039;&#039; file from the [http://owncloud.org/install/ ownCloud download page] to a temporary directory and extract it; this could look like&lt;br /&gt;
 cd /tmp&lt;br /&gt;
 wget http://download.owncloud.org/community/owncloud-6.0.1.tar.bz2&lt;br /&gt;
 tar -xjf owncloud-6.0.1.tar.bz2&lt;br /&gt;
Note that the extraction causes the tree of ownCloud files to appear in a directory called &#039;&#039;owncloud&#039;&#039;. Strictly speaking you could extract the file directly in /opt without first creating an &#039;&#039;owncloud&#039;&#039; directory by hand. However I like to keep an eye on processes like this. We can now move all the files from the tar into the prepared directory with a command such as&lt;br /&gt;
 cp -pR /tmp/owncloud/* /opt/owncloud&lt;br /&gt;
Here please note that all files in the tar file are owned by a user with UID and GID 65534, corresponding with &#039;&#039;nobody:nogroup&#039;&#039;. If your server or webserver setup require a different user/group, you should use &#039;&#039;chown&#039;&#039; to set this.&lt;br /&gt;
&lt;br /&gt;
===Publishing ownCloud in Apache2===&lt;br /&gt;
As we would like all files pertaining to the configuration of our server to live under &#039;&#039;/etc&#039;&#039;, we create a directory &#039;&#039;/etc/owncloud&#039;&#039;. Now, in this directory we&#039;ll create a file named &#039;&#039;apache.conf&#039;&#039; containing&lt;br /&gt;
 Alias /cloud /opt/owncloud&lt;br /&gt;
 &amp;lt;Directory /opt/owncloud&amp;gt;&lt;br /&gt;
     Options Indexes FollowSymLinks MultiViews&lt;br /&gt;
     AllowOverride All&lt;br /&gt;
     Order allow,deny&lt;br /&gt;
     allow from all&lt;br /&gt;
 &amp;lt;/Directory&amp;gt;&lt;br /&gt;
Publishing the ownCloud instance is now as easy as including this file in the relevant Apache (SSL) site configuration file. Under Debian, this means selecting the right file under &#039;&#039;/etc/apache2/sites-available/&#039;&#039; and insert the line&lt;br /&gt;
 Include /etc/owncloud/apache.conf&lt;br /&gt;
If you now reload Apache with a command such as &#039;&#039;service apache2 reload&#039;&#039;, you&#039;ll be able to surf to the URL of the pertaining site (e.g. https://www.saruman.biz/owncloud) and verify that the unconfigured owncloud instance is now accessible.&lt;br /&gt;
&lt;br /&gt;
==Configuring ownCloud==&lt;br /&gt;
We&#039;ll need &#039;&#039;&#039;a data directory&#039;&#039;&#039; for ownCloud. My recommendation is something like &#039;&#039;/data/owncloud&#039;&#039;, and since the web server is required to manipulate files in this directory, we&#039;ll make it owned by Debian&#039;s webserver user/group &#039;&#039;www-data:www-data&#039;&#039; (under other distributions, make sure to use the corresponding user/group). For this directory to be used by ownCloud, we&#039;ll symlink to it from &#039;&#039;/opt/owncloud&#039;&#039; with command:&lt;br /&gt;
 ln -s /data/owncloud /opt/owncloud/data&lt;br /&gt;
&lt;br /&gt;
We&#039;ll also need &#039;&#039;&#039;a database&#039;&#039;&#039; for ownCloud. To create one, we can start the MySQL client (&#039;&#039;mysql -u root -p&#039;&#039; and then the password) and create a database plus database user using&lt;br /&gt;
 mysql&amp;gt; create database owncloud;&lt;br /&gt;
 mysql&amp;gt; create user &#039;ownclouduser&#039;@&#039;localhost&#039; identified by &#039;&amp;lt;password1&amp;gt;&#039;;&lt;br /&gt;
 mysql&amp;gt; grant all on owncloud.* to &#039;ownclouduser&#039;@&#039;localhost&#039;;&lt;br /&gt;
&lt;br /&gt;
Now we can surf to the ownCloud instance page, and we&#039;ll find the startscreen asking for setup details. Provided the following details:&lt;br /&gt;
* Admin account: &#039;&#039;&#039;owncloudadmin/&amp;lt;password2&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
* Data folder: &#039;&#039;&#039;/opt/owncloud/data&#039;&#039;&#039;&lt;br /&gt;
* Database user: &#039;&#039;&#039;ownclouduser/&amp;lt;password1&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
* Database name: &#039;&#039;&#039;owncloud&#039;&#039;&#039;&lt;br /&gt;
* Database host: &#039;&#039;&#039;localhost&#039;&#039;&#039;&lt;br /&gt;
Once we&#039;ve finished the installation wizard, we&#039;ll be able to log in to ownCloud using the admin account (here &#039;&#039;owncloudadmin&#039;&#039;) and the corresponding password.&lt;br /&gt;
&lt;br /&gt;
If logging in works, then the following action will complete the configuration according to the LSB. We&#039;ll move the file &#039;&#039;/opt/owncloud/config/config.php&#039;&#039; that the installation wizard has created to our directory &#039;&#039;/etc/owncloud&#039;&#039; (if you like, you can also move the example configuration file &#039;&#039;config.sample.php&#039;&#039; for future reference). Then we symlink to it using&lt;br /&gt;
 ln -s /etc/owncloud/config.php /opt/owncloud/config/config.php&lt;br /&gt;
&lt;br /&gt;
==Configuring ownCloud==&lt;br /&gt;
===Initial setup===&lt;br /&gt;
===Using OpenLDAP as a backend===&lt;br /&gt;
===Theming ownCloud===&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3061</id>
		<title>E-mail server section</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=E-mail_server_section&amp;diff=3061"/>
		<updated>2014-02-04T20:58:37Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* E-mail server setup */  updated link to source article&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E-mail server setup==&lt;br /&gt;
What we want to accomplish here is the setup of a mail server with the following properties:&lt;br /&gt;
* can serve multiple mail domains&lt;br /&gt;
* can relay mail for other domains to other mail servers&lt;br /&gt;
* can have one or more mailboxes per domain&lt;br /&gt;
* users of these mailboxes can be virtual (do not need to have a Linux user account)&lt;br /&gt;
* can have multiple aliases per mailbox&lt;br /&gt;
* can forward mail for certain aliases to multiple mailboxes&lt;br /&gt;
For this type of mail server setup, we owe a great thankyou to [https://workaround.org/ispmail/squeeze Christoph Haas], whose advise has helped us create flexible and reliable mail servers since 2003.&lt;br /&gt;
&lt;br /&gt;
==Preparation==&lt;br /&gt;
We&#039;ll assume that the server currently has no mailserver installed, at least no other than the default &#039;&#039;exim&#039;&#039; mailserver. Furthermore, the server is already fitted with MySQL, and this database is running without problems.&lt;br /&gt;
&lt;br /&gt;
The hostname of the server must be set correctly, so that &#039;&#039;hostname -f&#039;&#039; returns a valid DNS name, like &#039;&#039;lighthouse.saruman.biz.&#039;&#039;. It might also be an internal name like &#039;&#039;lighthouse.saruman.lan.&#039;&#039; but that will require us to give extra attention to the name under which Postfix will contact its collegues on the Internet. Also, the server can correctly [Networking_section#DNS_resolution_under_Debian | resolve DNS names] like [http://www.debian.org www.debian.org], preferably by running it&#039;s own caching DNS server.&lt;br /&gt;
&lt;br /&gt;
The server is kept on the correct date and time using NTP, TCP port 25 is open on the server, the ISP will allow connections from Internet to this port, and if there&#039;s a firewall running on this server, then it has port 25 open so as to not block incoming e-mail.&lt;br /&gt;
&lt;br /&gt;
==Software installation==&lt;br /&gt;
As a first step, we use [[APT and aptitude|apt or aptitude]] to make sure that our server is up-to-date. Then we can install the necessary software packages. Under Debian 5.0 &amp;quot;Lenny&amp;quot;, the (single) packages is:&lt;br /&gt;
* &#039;&#039;postfix&#039;&#039;, the mail server itself - this includes the &amp;quot;virtual package&amp;quot; postfix-tls, that we want to use to secure connections to Postfix with the TLS protocol&lt;br /&gt;
At the same time we can - and must - purge the following packages:&lt;br /&gt;
* exim4&lt;br /&gt;
* exim4-base&lt;br /&gt;
* exim4-daemon-light&lt;br /&gt;
* exim4-config&lt;br /&gt;
In &#039;&#039;aptitude&#039;&#039;, only press &amp;quot;go&amp;quot; when you&#039;ve marked all four of these packages &amp;quot;purge&amp;quot;, or you cannot install postfix.&lt;br /&gt;
&lt;br /&gt;
When installing the postfix package, the Debian installer script will ask you several questions, which you can answer like this:&lt;br /&gt;
* General type of mail configuration: Internet site&lt;br /&gt;
* System mail name: the FQDN of the mail server that you&#039;ve verified in the previous section. Note that the script will try to guess the DNS name, but that might yield a DNS name with a trailing dot. That is technically correct, but the installation script will barf. Remove the trailing dot before hitting &amp;amp;lt;enter&amp;gt;!&lt;br /&gt;
* Postmaster mail address: the address that all mail should go to that is addressed to &amp;quot;root&amp;quot; and &amp;quot;postmaster&amp;quot;.&lt;br /&gt;
* Domain list: give the list of all domains that the machine can consider itself the FINAL destination for. This should at a minimum include an empty value, &amp;quot;localhost&amp;quot; and the FQDN of the machine itself (no trailing dots!); however, if you&#039;re running your own mail domain, you can also add that (e.g. &amp;quot;saruman.biz&amp;quot;). Thus, the list could look like this:&lt;br /&gt;
 saruman.biz, lighthouse.saruman.lan, localhost.saruman.lan, , localhost&lt;br /&gt;
* Force synchronous updates? We think that&#039;s not necessary, but please read the question and decide for yourself&lt;br /&gt;
* Local networks: something like &#039;&#039;127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.67.0/24&#039;&#039; (the default, augmented with your local IP range)&lt;br /&gt;
* Mailbox size limits: you can give postfix a limit in bytes, but we&#039;re going to use one single big mailbox for all users, so we cannot let Postfix guard it. Leave it at 0 (zero) so we don&#039;t have a size limit.&lt;br /&gt;
* Character for local address extension: we leave it at &#039;&#039;+&#039;&#039;&lt;br /&gt;
* Internet protocols to use: currently we don&#039;t have IPv6 support, so there&#039;s no sense in letting Postfix try to serve IPv6. We choose &#039;&#039;ipv4&#039;&#039; only.&lt;br /&gt;
With the above data, the Debian install script for Postfix can do its job and configure Postfix with some basic settings.&lt;br /&gt;
&lt;br /&gt;
Now that Postfix is installed, we can install some dependent packages (we could install them in the same run, but if anything goes amiss with the postfix installation, then these packages are going to remain unconfigured as well):&lt;br /&gt;
* &#039;&#039;postfix-doc&#039;&#039;, the accompanying documentation;&lt;br /&gt;
* &#039;&#039;postfix-mysql&#039;&#039;, necessary to have Postfix talk to our MySQL server;&lt;br /&gt;
* &#039;&#039;postfix-pcre&#039;&#039; to be able to parse regular expressions, which which we can combat spam;&lt;br /&gt;
* &#039;&#039;dovecot-imapd&#039;&#039; is a daemon that will provide your users with IMAP access to their mail;&lt;br /&gt;
* &#039;&#039;dovecot-pop3d&#039;&#039; is another daemon, but for the POP3 protocol.&lt;br /&gt;
&lt;br /&gt;
==Virtual Mailman creation==&lt;br /&gt;
When we&#039;re done, we&#039;ll need a &amp;quot;system user&amp;quot;, a sort of virtual mailman that is the owner of all mailboxes that we&#039;re serving. We suggest the name &amp;quot;vmail&amp;quot; for this user. Note: this user does not get his own mailbox (i.e. there&#039;s no mailbox at vmail@saruman.biz).&lt;br /&gt;
&lt;br /&gt;
To create this user, and his home directory, we can run the following commands:&lt;br /&gt;
 groupadd -g 120 vmail&lt;br /&gt;
 useradd -g vmail -u 120 vmail -d /data/vmail -m -s /bin/false&lt;br /&gt;
As you see, we&#039;ve chosen a group ID and user ID of 120 (after confirming that this ID was not taken by another group or user, by checking &#039;&#039;/etc/passwd&#039;&#039; and &#039;&#039;/etc/group&#039;&#039;. Furthermore, we&#039;ve decided to keep the &#039;&#039;vmail&#039;&#039; user&#039;s home directory not under &#039;&#039;/home/vmail&#039;&#039;, but in a special place where we&#039;re going to expect server data to reside - in our server, the &#039;&#039;/data&#039;&#039; directory (which is a RAID-5 array mounted under root). By adding &#039;&#039;-m&#039;&#039;, we&#039;ve actually created the home directory, and adding &#039;&#039;-s /bin/false&#039;&#039; makes totally sure that the user &#039;&#039;vmail&#039;&#039; can never ever log in - even if we&#039;ve not created a password for this user, so &#039;&#039;vmail&#039;&#039; shouldn&#039;t be able to log in anyway. Better safe than sorry.&lt;br /&gt;
&lt;br /&gt;
To tell Postfix that this &#039;&#039;vmail&#039;&#039; user is someone special, we run&lt;br /&gt;
 postconf -e virtual_uid_maps=static:120&lt;br /&gt;
 postconf -e virtual_gid_maps=static:120&lt;br /&gt;
That makes postfix understand that all mail for the virtual mail domains must be written to disk with these specified user and group ID&#039;s.&lt;br /&gt;
&lt;br /&gt;
==MySQL configuration==&lt;br /&gt;
&lt;br /&gt;
===Database preparation===&lt;br /&gt;
We will use the MySQL database to record data on our mail system, and then give our Postfix access to this database so that it can read its configuration from there. For starters, we&#039;ll create a MySQL database named &amp;quot;vmail&amp;quot;, and a MySQL user named &amp;quot;vmail_admin&amp;quot; that can read all necessary data from that &amp;quot;vmail&amp;quot; database. Then, we create the necessary tables, and a view that links these tables. We do this with the MySQL client &#039;&#039;mysql&#039;&#039;. However, we&#039;re quite lazy, so we don&#039;t create this database by hand (that&#039;s error-prone), but by use of a script [[create.vmail.sql]]. To this end, feed the [[create.vmail.sql]] script into the &#039;&#039;mysql&#039;&#039; client like this:&lt;br /&gt;
 mysql -u root -p &amp;lt; create.vmail.sql&lt;br /&gt;
(This of course assumes you have &#039;&#039;create.vmail.sql&#039;&#039; in your current working directory; if not you can include the path to the file.) Simply give the MySQL root user password, and the script creates the database, the user, the necessary tables, and the view.&amp;lt;br&amp;gt;&lt;br /&gt;
A note of caution: it is never a good idea to just run scripts without a proper understanding of what it does. Especially with MySQL, it will be advantageous if you understand the SQL commands. Open the script in a text editor, open the [http://dev.mysql.com/doc/refman/5.0/en/ MySQL command reference], and trace back what the script does exactly.&lt;br /&gt;
&lt;br /&gt;
===Inserting data===&lt;br /&gt;
Next up, we fill the database with the first sets of values (either test data or the first of our production data). We&#039;ll start off with the virtual domains that we&#039;re hosting, by running the mysql client and feeding it information like this:&lt;br /&gt;
 mysql -u root -p vmail&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (id, vdomain) VALUES (1, &#039;saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;wiki.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_domains (vdomain) VALUES (&#039;shop.saruman.biz&#039;);&lt;br /&gt;
This has the effect of creating three entries. You can check that everything worked as planned by executing&lt;br /&gt;
 mysql&amp;gt; select * from virtual_domains;&lt;br /&gt;
Note: only the first entry needs an &#039;&#039;id&#039;&#039; value, because in MySQL we&#039;ve defined that field as AUTO_INCREMENT. After creating your first virtual domain in the table, you never have to use a statement like the first INSERT again, only statements like the other two.&lt;br /&gt;
&lt;br /&gt;
Now the MySQL database has the information needed by Postfix to recognise that you have three virtual mail domains (namely the three domains in the VALUES section) for which it hosts virtual mailboxes. Postfix cannot read this information yet, but that&#039;ll be taken care of in the next section.&lt;br /&gt;
&lt;br /&gt;
Whle still within the mysql client, we can now create users:&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (id, domain_id, user, passwd) VALUES (1, 1, &#039;jan&#039;, MD5(&#039;JanSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (1, &#039;mike&#039;, MD5(&#039;MikeSecret&#039;));&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_users (domain_id, user, passwd) VALUES (3, &#039;shopkeeper&#039;, MD5(&#039;ShopSecret&#039;));&lt;br /&gt;
This has the effect of creating three users &amp;quot;jan&amp;quot; (in domain saruman.biz), &amp;quot;mike&amp;quot; (in domain saruman.biz) and &amp;quot;shopkeeper&amp;quot; (in domain shop.saruman.biz). Again, the &#039;&#039;id&#039;&#039; value is only ever needed in the first statement, because from now on every user addition will auto-increment &#039;&#039;id&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The passwords shown are encrypted with MD5, and put in the &#039;&#039;passwd&#039;&#039; field. Later on, the users will be able to access their mailboxes using this password; we won&#039;t tell Postfix anything about them, because it doesn&#039;t need the passwords. You can check the content of the &#039;&#039;virtual_users&#039;&#039; table with the right &amp;quot;select&amp;quot; statement, and you can now also see that the view &#039;&#039;view-users&#039;&#039; works:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_users;&lt;br /&gt;
 mysql&amp;gt; select * from view_users;&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;re going to add some aliases, which are alternative e-mail addresses for the users; their primary e-mail address can already be seen in the &#039;&#039;view_users&#039;&#039; view, but perhaps you also want mail to &amp;quot;webmaster@shop.saruman.biz&amp;quot; to arrive at one or more mailboxes, e.g. in the mailbox for user &amp;quot;shopkeeper&amp;quot; (within domain &amp;quot;shop.saruman.biz&amp;quot;) and this guy&#039;s home address (&amp;quot;j.doe@example.com&amp;quot;). Furthermore, we&#039;ll define catchall-addresses for all domains, that&#039;ll send all mail for which no mailbox can be found to the mailbox of user Mike (for the first two domains) and Webmaster (for shop.saruman.biz; Webmaster himself is an alias yet again, that points to shopkeeper@shop.saruman.biz). To create the catchall, leave out a value for the source address. This creates the empty value for source that will be expanded (using source@domain) to &amp;quot;@domain&amp;quot;.&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (id, domain_id, source, destination)&lt;br /&gt;
        VALUES (1, 2, &#039;webmaster&#039;, &#039;shopkeeper@shop.saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, source, destination)&lt;br /&gt;
        VALUES (2, &#039;webmaster&#039;, &#039;j.doe@example.com&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (1, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (2, &#039;mike@saruman.biz&#039;);&lt;br /&gt;
 mysql&amp;gt; INSERT INTO virtual_aliases (domain_id, destination)&lt;br /&gt;
        VALUES (3, &#039;webmaster@saruman.biz&#039;);&lt;br /&gt;
 &lt;br /&gt;
Again, we don&#039;t need to add the &#039;&#039;id&#039;&#039; value any more after the first ever insertion into this table.&lt;br /&gt;
&lt;br /&gt;
We can check the result by running a select statement against the &#039;&#039;virtual_aliases&#039;&#039; table and &#039;&#039;view_aliases&#039;&#039; view:&lt;br /&gt;
 mysql&amp;gt; select * from virtual_aliases;&lt;br /&gt;
 mysql&amp;gt; select * from view_aliases;&lt;br /&gt;
&lt;br /&gt;
== Postfix configuration for MySQL lookups==&lt;br /&gt;
Next, we&#039;re going to tell Postfix to use the &#039;&#039;vmail&#039;&#039; database, and also how to read the database (Postfix never writes the MySQL database). To this end, we&#039;re going to create three configuration files in directory &#039;&#039;/etc/postfix&#039;&#039;. We&#039;ll start off with one configuration file, with which Postfix can determine if a domain name is among the domain(s) that it&#039;s actually hosting mailboxes for. Then we&#039;ll create the config file that checks the table that contains all the users that have a virtual mailbox, and finally we create the lookup for the table with all the aliases.&lt;br /&gt;
&lt;br /&gt;
===Virtual mail domains lookup===&lt;br /&gt;
&lt;br /&gt;
Create file &#039;&#039;/etc/postfix/mysql-virtual-domains.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM virtual_domains WHERE vdomain=&#039;%s&#039;&lt;br /&gt;
Next, we tell postfix to check this configuration file when it needs to check &amp;quot;virtual_mailbox_domains&amp;quot;:&lt;br /&gt;
 postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-virtual-domains.cf&lt;br /&gt;
Use of this configuration file in postfix has the effect of returning &amp;quot;yes&amp;quot; when checking our database for the domain part of an email address. Naturally, this configuration file has to be fitted with the actual &#039;&#039;vmail_admin&#039;&#039; password rather than our example &amp;quot;SuperSecret&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
=== Virtual mail user lookup===&lt;br /&gt;
Create the file &#039;&#039;/etc/postfix/mysql-virtual-mailbox-maps.cf&#039;&#039; with the following content:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT 1 FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
Next, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_mailbox_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
The lookup of virtual mailboxes should work with the data we&#039;ve put into the database previously. i.e.&lt;br /&gt;
 postmap -q jan@saruman.biz mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf&lt;br /&gt;
should return a &#039;&#039;&#039;1&#039;&#039;&#039; to acknowledge that &amp;quot;jan@saruman.biz&amp;quot; is indeed a virtual mailbox in our Postfix configuration.&lt;br /&gt;
&lt;br /&gt;
=== Virtual alias lookup===&lt;br /&gt;
Create another cf file at &#039;&#039;/etc/postfix/mysql-virtual-alias-maps.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT destination FROM view_aliases WHERE email=&#039;%s&#039;&lt;br /&gt;
And create yet another cf file at &#039;&#039;/etc/postfix/mysql-email2email.cf&#039;&#039;:&lt;br /&gt;
 user = vmail_admin&lt;br /&gt;
 password = SuperSecret&lt;br /&gt;
 hosts = 127.0.0.1&lt;br /&gt;
 dbname = vmail&lt;br /&gt;
 query = SELECT email FROM view_users WHERE email=&#039;%s&#039;&lt;br /&gt;
&lt;br /&gt;
Again, we tell Postfix that this mapping file is supposed to be used for the &#039;&#039;virtual_alias_maps&#039;&#039; mapping:&lt;br /&gt;
 postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf&lt;br /&gt;
The lookup of virtual aliases should now work as designed:&lt;br /&gt;
 postmap -q shopkeeper@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
 postmap -q webmaster@shop.saruman.biz mysql:/etc/postfix/mysql-virtual-alias-maps.cf&lt;br /&gt;
If you&#039;ve put in the data from the previous section, then both commands should return the same result: &#039;&#039;shopkeeper@saruman.biz&#039;&#039;. This shows that Postfix will deliver  mail to shopkeeper or to webmaster to the mailbox of shopkeeper.&lt;br /&gt;
&lt;br /&gt;
===Finishing up configuration files===&lt;br /&gt;
When everything works as planned, then we secure the configuration files against prying eyes. Remember, the configuration files contain the user/password combination which which to access the &#039;&#039;vmail&#039;&#039; SQL database. The &#039;&#039;vmail_admin&#039;&#039; user has only read rights, and passwords in there are encrypted, but nevertheless, this is information we need to protect. Thus:&lt;br /&gt;
 chown root:postfix /etc/postfix/mysql-*.cf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/postfix/mysql-*.cf&lt;br /&gt;
This protects all four configuration files since only root can write them, members of group &#039;&#039;postfix&#039;&#039; can read them, and the rest of the world cannot access them at all.&lt;br /&gt;
&lt;br /&gt;
==Configuring mail delivery through Dovecot LDA==&lt;br /&gt;
E-mails get delivered to the virtual mailboxes by means of a Mail Delivery Agent (MDA). With Postfix, the standard MDA for delivery to virtual mailboxes is called &#039;&#039;virtual&#039;&#039;, but we&#039;re not going to use that; we&#039;re going to use &#039;&#039;[http://wiki.dovecot.org/LDA Dovecot LDA]&#039;&#039;, which is a program called &#039;&#039;deliver&#039;&#039;. By the way, the abbreviation LDA stands for Local Delivery Agent, which of course means more or less the same as MDA.&lt;br /&gt;
===Enabling the Dovecot daemon===&lt;br /&gt;
To make Postfix use Dovecot LDA, we add the following line to &#039;&#039;/etc/postfix/master.cf&#039;&#039;:&lt;br /&gt;
 dovecot   unix  -       n       n       -       -       pipe&lt;br /&gt;
     flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}&lt;br /&gt;
This declares the service &amp;quot;dovecot&amp;quot; to mean using the program &#039;&#039;/usr/lib/dovecot/deliver&#039;&#039; with the right parameters. If we now let Postfix reload its files, it&#039;ll learn about this new service. Subsequently we can instruct Postfix to start using it, by declaring service &amp;quot;dovecot&amp;quot; to be the virtual transport of choice, and specifying one Dovecot-specific variable:&lt;br /&gt;
 postfix reload&lt;br /&gt;
 postconf -e virtual_transport=dovecot&lt;br /&gt;
 postconf -e dovecot_destination_recipient_limit=1&lt;br /&gt;
===Dovecot default configuration===&lt;br /&gt;
Now to configure Dovecot itself: open &#039;&#039;/etc/dovecot/dovecot.conf&#039;&#039; with your favourite editor [[vim]]; first make sure the &#039;&#039;protocols =&#039;&#039; line reads&lt;br /&gt;
 protocols = imap imaps pop3 pop3s&lt;br /&gt;
(which it should by default). The second setting is quite crucial. By default, the location of the mail directories is found automatically by Dovecot, but here that won&#039;t work. Find the line that reads &#039;&#039;#mail_location =&#039;&#039;, and change it to&lt;br /&gt;
 mail_location = maildir:/data/vmail/%d/%n/Maildir&lt;br /&gt;
This will look for mail in directory &#039;&#039;/data/vmail/&#039;&#039;&#039;DOMAIN&#039;&#039;&#039;/&#039;&#039;&#039;USER&#039;&#039;&#039;/Maildir&#039;&#039;, and expect this directory to be in &amp;quot;maildir&amp;quot; format.&lt;br /&gt;
Next look for a section called &amp;quot;auth default&amp;quot;. First define the allowed authentication mechanisms:&lt;br /&gt;
 mechanisms = plain login&lt;br /&gt;
Then inside that same section you need to uncomment:&lt;br /&gt;
 passdb sql {&lt;br /&gt;
     args = /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 }&lt;br /&gt;
which tells Dovecot that the passwords are stored in an SQL database (it&#039;s obvious that we&#039;ll now have to create this conf-file) and:&lt;br /&gt;
 userdb static {&lt;br /&gt;
     args = uid=120 gid=120 home=/data/vmail/%d/%n allow_all_users=yes&lt;br /&gt;
 }&lt;br /&gt;
to tell Dovecot where the mailboxes are located. This is similar to the &#039;&#039;mail_location&#039;&#039; setting. Next task: comment out the section &#039;&#039;passdb pam&#039;&#039;, so that Dovecot doesn&#039;t accidentally try to service local users as well.&lt;br /&gt;
&lt;br /&gt;
Next up: tell Dovecot to handle IMAP the same as previous versions of this virtual mailserver have - this can prove to be quite tricky if you already have mailboxes full of mail, put there by e.g. Courier-IMAP. What works for us, is&lt;br /&gt;
 namespace private {&lt;br /&gt;
     separator = .&lt;br /&gt;
     prefix = &lt;br /&gt;
     inbox = yes&lt;br /&gt;
 }&lt;br /&gt;
However, your mileage may vary.&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to comment out the &#039;&#039;passdb pam&#039;&#039; sections, since we&#039;re not hosting mail for local users.&lt;br /&gt;
&lt;br /&gt;
Next up, we&#039;ll edit the section &#039;&#039;socket listen&#039;&#039; so that Dovecot can access the user database (master section), and our Postfix mailserver can access Dovecot (client section):&lt;br /&gt;
 socket listen {&lt;br /&gt;
   master {&lt;br /&gt;
     path = /var/run/dovecot/auth-master&lt;br /&gt;
     mode = 0600&lt;br /&gt;
     user = vmail&lt;br /&gt;
   }&lt;br /&gt;
   client {&lt;br /&gt;
     path = /var/spool/postfix/private/auth&lt;br /&gt;
     mode = 0660&lt;br /&gt;
     user = postfix&lt;br /&gt;
     group = postfix&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Finally, the protocol section, where we specify log files, an address to put in mails when we send out nondelivery reports, and a place to store scripts:&lt;br /&gt;
 protocol lda {&lt;br /&gt;
     log_path = /var/log/appslog/mail/dovecot-deliver.log&lt;br /&gt;
     auth_socket_path = /var/run/dovecot/auth-master&lt;br /&gt;
     postmaster_address = postmaster@saruman.biz&lt;br /&gt;
     mail_plugins = cmusieve&lt;br /&gt;
     global_script_path = /data/vmail/globalsieverc&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
You could change the log path to &amp;quot;log_path =&amp;quot; With a empty logpath syslog will log the events. &lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve finished the Dovecot configuration file, we need to create a fitting MySQL configuration file for Dovecot. The file is &#039;&#039;/etc/dovecot/dovecot-sql.conf&#039;&#039;, and its contents are&lt;br /&gt;
 driver = mysql&lt;br /&gt;
 connect = host=127.0.0.1 dbname=vmail user=vmail_admin password=SuperSecret&lt;br /&gt;
 default_pass_scheme = PLAIN-MD5&lt;br /&gt;
 password_query = SELECT email as user, passwd as password FROM view_users WHERE email=&#039;%u&#039;;&lt;br /&gt;
When you&#039;ve created this file (as root), change the attributes of &#039;&#039;dovecot-sql.conf&#039;&#039; and &#039;&#039;dovecot.conf&#039;&#039;, and then restart Dovecot to start using the new configuration. Note: &#039;&#039;dovecot.conf&#039;&#039; needs to be read by Postfix, hence the group ownership for the file.&lt;br /&gt;
 chmod u=rw,g=,o= /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
 chgrp vmail /etc/dovecot/dovecot.conf&lt;br /&gt;
 chmod u=rw,g=r,o= /etc/dovecot/dovecot.conf&lt;br /&gt;
 /etc/init.d/dovecot restart&lt;br /&gt;
&lt;br /&gt;
To get some more logging in the case something goes wrong. Uncomment the folling and change to yes.&lt;br /&gt;
 auth_verbose = yes&lt;br /&gt;
 auth_debug = yes&lt;br /&gt;
 auth_debug_passwords = yes&lt;br /&gt;
&lt;br /&gt;
===Dovecot SSL configuration===&lt;br /&gt;
Out of the (Debian) box, Dovecot is SSL-enabled. We&#039;ll now replace the generic SSL-certificate, generated for the host by the Dovecot installation script, by our own certificate. To ths end, we first [[Creating_digital_certificates_with_our_root_certificate | generate an appropriate certificate]], e.g. an SSL wildcard certificate: &amp;quot;*.saruman.biz&amp;quot;. This results in a public and a private certificate, both of which must be placed somewhere where Dovecot expects them and can read them.&lt;br /&gt;
&lt;br /&gt;
By default, Dovecot expects the following locations/filenames/owner/attributes:&lt;br /&gt;
 /etc/ssl/certs/dovecot.pem    -rw-r--r--  root:dovecot  4624 bytes&lt;br /&gt;
 /etc/ssl/private/dovecot.pem  -rw-------  root:dovecot  1743 bytes&lt;br /&gt;
If we may make a suggestion: rename the generated certificates in both locations to dovecot.pem.bak, place your generated certificates in their place, and set the owner/permissions like displayed here.&lt;br /&gt;
&lt;br /&gt;
However, if you&#039;ve generated your own keys, you might have used a passphrase on the private key. You&#039;ll have to tell dovecot about it in its configuration file /etc/dovecot/dovecot.conf. To this end, edit the corresponding section by uncommenting the &amp;quot;ssl_&amp;quot; lines, and using your private key password (e.g. &amp;quot;zM7Ertq12&amp;quot;) in the appropriate line:&lt;br /&gt;
 ssl_cert_file = /etc/ssl/certs/dovecot.pem&lt;br /&gt;
 ssl_key_file = /etc/ssl/private/dovecot.pem&lt;br /&gt;
 &lt;br /&gt;
 # If key file is password protected, give the password here. Alternatively&lt;br /&gt;
 # give it when starting dovecot with -p parameter.&lt;br /&gt;
 ssl_key_password = zM7Ertq12&lt;br /&gt;
Naturally you are free to place the keys in a different location, and/or use a different name...&lt;br /&gt;
&lt;br /&gt;
==Finishing up==&lt;br /&gt;
&lt;br /&gt;
This is a good moment to test your configuration, if you haven&#039;t been able to test your work inbetween. If everything works as expected, you can add bells and whistles to your configuration.&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;smtpd&#039;&#039; TLS encryption===&lt;br /&gt;
The first addition we&#039;d like to present covers the way Postfix handles incoming connections. Since authentication works, we can have Postfix distrust every (unauthenticated) connection:&lt;br /&gt;
 postconf -e mynetworks=&lt;br /&gt;
Furthermore, since a default SSL certificate is installed by the Debian Postfix installation routine, we can encrypt all our connections using TLS; we enforce this using&lt;br /&gt;
 postconf -e smtpd_use_tls=yes&lt;br /&gt;
 postconf -e smtpd_tls_auth_only=yes&lt;br /&gt;
Of course, you need to adjust the settings of your IMAP client so that it properly uses TLS and properly authenticates itself.&lt;br /&gt;
&lt;br /&gt;
If TLS works, you&#039;ll probably want to change the certificate as you have for Dovecot in the previous section. This is again pretty easy. If you haven&#039;t yet, now is the time to [[Creating_digital_certificates_with_our_root_certificate | creating that custom SSL certificate]] for our mail server - but you have to make sure that you DON&#039;T use a password on the private key. Unlike Dovecot, Postfix cannot be told the password to the private key somewhere.&lt;br /&gt;
&lt;br /&gt;
For starters, look at the TLS-section of your &#039;&#039;main.cf&#039;&#039; that you currently have. Chances are a big chunk of it looks like this:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Now all you need to do is replace the name of the snakeoil-keys with those of appropriate ssl-certificates, the private key of which needs to be NOT passphrase-protected. For this you could copy the Dovecot certificates, if you strip that passphrase in the manner described in the [[Creating_digital_certificates_with_our_root_certificate#Creating_an_SSL_certificate | SSL certificate section]]. The &#039;&#039;main.cf&#039;&#039; then would become:&lt;br /&gt;
 # TLS parameters&lt;br /&gt;
 smtpd_tls_cert_file=/etc/ssl/certs/postfix.pem&lt;br /&gt;
 smtpd_tls_key_file=/etc/ssl/private/postfix.key&lt;br /&gt;
 smtpd_use_tls=yes&lt;br /&gt;
Restart Postfix, and presto.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other additions ===&lt;br /&gt;
If everything &#039;&#039;still&#039;&#039; works after these changes, then congratulations, you now have a powerful, flexible and pretty secure mail setup. Of course, there are always points for improvements. We&#039;ll cover these in separate pages. One page that we want to direct you to now, is&lt;br /&gt;
* [[Antispam measures]] for our Postfix mailserver&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3060</id>
		<title>Your own ownCloud</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Your_own_ownCloud&amp;diff=3060"/>
		<updated>2014-01-04T09:59:26Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: start&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;ownCloud&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
In this day and age where many people are more and more dependant on information, cloud technology offers a way to unlock your information to you, wherever you are, on most any device. However, there&#039;s no telling what the cloud companies that you entrust with your information will do with that info - let alone nosy intelligence agencies from various countries around the world. My privacy [https://chronicle.com/article/Why-Privacy-Matters-Even-if/127461/ matters to me]!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[http://owncloud.org/ ownCloud]&#039;&#039;&#039; is a free and open source alternatives for many cloud offerings such as Google Drive and DropBox, as it gives you the ability to share and sync files from your own server, but it does [http://owncloud.org/features/ much more] - added bonus, I say...&lt;br /&gt;
&lt;br /&gt;
___TOC___&lt;br /&gt;
==Introduction==&lt;br /&gt;
ownCloud broadly comes in two flavours: the open source, free &amp;quot;community edition&amp;quot; and the open source, paid &amp;quot;enterprise edition&amp;quot;. We&#039;re going to install the community edition here. The goal will be to have a way to share files between groups of people, most of which will have an account on our server.&lt;br /&gt;
&lt;br /&gt;
==Installing ownCloud==&lt;br /&gt;
&lt;br /&gt;
===Preparing your server===&lt;br /&gt;
&lt;br /&gt;
===Getting ownCloud files on your server===&lt;br /&gt;
===Publishing ownCloud in Apache2===&lt;br /&gt;
==Configuring ownCloud==&lt;br /&gt;
===Initial setup===&lt;br /&gt;
===Using OpenLDAP as a backend===&lt;br /&gt;
===Theming ownCloud===&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3059</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=3059"/>
		<updated>2014-01-04T09:24:19Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: rearrange and add ownCloud&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users. If you are interested in my work on [http://www.dya.info DYA|Infrastructure], please visit the [https://dya-knowledge.sogeti.nl/ SmartMart demo site].&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian Squeeze base server]] is a howto on the installation of a very basic Linux box under Lenny (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; for [[software-based RAID]] contains our ideas and observations on redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Authentication and security&#039;&#039;&#039;&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Your own LAMP server&#039;&#039;&#039;&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Other server apps&#039;&#039;&#039;&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
* How to create [[your own ownCloud]] server (and here&#039;s [http://www.thecomputerkid.com/2013/06/why-you-should-use-owncloud.html why] you should do this)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Database_101&amp;diff=3058</id>
		<title>Database 101</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Database_101&amp;diff=3058"/>
		<updated>2013-06-03T03:54:11Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* MySQL commands */  userdrop&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MySQL installation ==&lt;br /&gt;
As with any package to be installed: use aptitude, update your APT, then make sure all your (other) software is up-to-date. Then find package &#039;&#039;mysql-server&#039;&#039; - under Debian 5.0 &amp;quot;Lenny&amp;quot; it&#039;ll be version 5.0.51a-something. Installing it will also automatically install some dependent packages, like mysql-common, mysql-client etcetera. So after downloading some 40MiB of files, MySQL is installed. The installation script under Debian Lenny asks you for a password for the MySQL root user. Think up a strong password for the MySQL root user; something like &#039;&#039;waYacUbaT2uW&#039;&#039;. DON&#039;T use this example password, [http://www.pctools.com/guides/password/ generate your own one!]. DO NOT use the password of the Linux &#039;&#039;root&#039;&#039; user.&lt;br /&gt;
&lt;br /&gt;
Should you consult [http://dev.mysql.com/doc/refman/5.0/en/unix-post-installation.html the official MySQL documentation], you might see mention of the &#039;&#039;mysql_install_db&#039;&#039; script - do not worry about that, since Debian has run it for you when it was setting up the database.&lt;br /&gt;
&lt;br /&gt;
The standard user accounts that have been created by the installation script are:&lt;br /&gt;
* &#039;root&#039;@&#039;localhost&#039;&lt;br /&gt;
* &#039;root&#039;@&#039;&amp;lt;hostname&amp;gt;&#039;&lt;br /&gt;
* &#039;root&#039;@&#039;127.0.0.1&#039;&lt;br /&gt;
All three root accounts are secured with the same password, the one you specified when installing the package &#039;&#039;mysql-server&#039;&#039;.&lt;br /&gt;
----&lt;br /&gt;
&#039;&#039;&#039;NOTE for Debian 4.0 &amp;quot;Etch&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
When you install MySQL under Etch, there are two root accounts with empty passwords, and two anonymous accounts. NOT safe! You&#039;ll want to rectify this in order to secure your MySQL server. Please take the following steps. Start the MySQL client from the command line:&lt;br /&gt;
 mysql -u root&lt;br /&gt;
Then, from the mysql client prompt, set the password for the MySQL root users. They can be treated as two different accounts, but we don&#039;t recommend that. We thus give both accounts the same password:&lt;br /&gt;
 mysql&amp;gt; SET PASSWORD FOR &#039;root&#039;@&#039;localhost&#039; = PASSWORD(&#039;waYacUbaT2uW&#039;);&lt;br /&gt;
 mysql&amp;gt; SET PASSWORD FOR &#039;root&#039;@&#039;&amp;lt;hostname&amp;gt;&#039; = PASSWORD(&#039;waYacUbaT2uW&#039;);&lt;br /&gt;
Furthermore, there are two anonymous accounts created. These also have no password, and get full permission on the &#039;&#039;test&#039;&#039; database, as well as on any database who&#039;s name begins with &#039;&#039;test_&#039;&#039;. These accounts can be fitted with a password (like we did for root - just use two quotes with nothing in between them, instead of two quotes with &#039;&#039;root&#039;&#039; in between), or they can be removed - which we recommend. The (single) command for this is:&lt;br /&gt;
&amp;lt;pre&amp;gt;mysql&amp;gt; DROP USER &#039;&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;End of NOTE&#039;&#039;&#039;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
To verify the installation you might want to take some of the following steps:&lt;br /&gt;
* run &#039;&#039;mysqlshow -u root -p&#039;&#039;, and see if that command outputs at least two databases (&#039;&#039;information_schema&#039;&#039; and &#039;&#039;mysql&#039;&#039;);&lt;br /&gt;
* check out the settings of your MySQL server by running &#039;&#039;mysqladmin -u root -p variables&#039;&#039; (piping the output to &#039;&#039;less&#039;&#039; or a file, if necessary);&lt;br /&gt;
* have a peek in &#039;&#039;/var/lib/mysql&#039;&#039;; the database data files should be there;&lt;br /&gt;
* check &#039;&#039;/var/log&#039;&#039; for two logfiles &#039;&#039;mysql.err&#039;&#039; and &#039;&#039;mysql.log&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Moving the MySQL databases==&lt;br /&gt;
By default the location of your Debian MySQL databases is &#039;&#039;/var/lib/mysql/&amp;lt;database&amp;gt;&#039;&#039;. However, sometimes you wish your databases to be in a different location. E.g. &#039;&#039;/data/mysql&#039;&#039;, where &#039;&#039;/data&#039;&#039; is a mounted dedicated RAID array. Or perhaps even &#039;&#039;/data/mysql&#039;&#039; is its own array.&lt;br /&gt;
&lt;br /&gt;
Whatever the reason, to move &#039;&#039;all&#039;&#039; MySQL databases from &#039;&#039;/var/lib/mysql&#039;&#039; to another location, you can follow these steps:&lt;br /&gt;
* Create the new directory, e.g. &#039;&#039;/data/mysql&#039;&#039;&lt;br /&gt;
* Make this directory owned by user/group &#039;&#039;mysql&#039;&#039;&lt;br /&gt;
 cd /data&lt;br /&gt;
 mkdir mysql&lt;br /&gt;
 chown mysql:mysql mysql&lt;br /&gt;
* Shut down the database server with one of the following commands:&lt;br /&gt;
 mysqladmin -u root -p shutdown&lt;br /&gt;
 invoke-rc.d mysql stop&lt;br /&gt;
* Make a backup copy of &#039;&#039;/etc/mysql/my.cnf&#039;&#039;, then edit this file. Find the section &#039;&#039;[mysqld]&#039;&#039; and change the line &#039;&#039;datadir         = /var/lib/mysql&#039;&#039; to&lt;br /&gt;
 datadir         = /data/mysql&lt;br /&gt;
* As root, move (or better yet: copy) &#039;&#039;all&#039;&#039; of the content of &#039;&#039;/var/lib/mysql&#039;&#039; over to &#039;&#039;/data/mysql&#039;&#039;. Make sure you don&#039;t accidentally change the ownership or permissions of the files and folders in the &#039;&#039;/var/lib/mysql&#039;&#039; folder. We expect each and every file and folder to be owned by &#039;&#039;mysql:mysql&#039;&#039;. Copy command would be (as root):&lt;br /&gt;
 cp -p -r /var/lib/mysql/* /data/mysql&lt;br /&gt;
* Check and doublecheck your &#039;&#039;my.cnf&#039;&#039; settings and your database file owners, attributes and size. After the next step, there &#039;&#039;may&#039;&#039; be no way back!&lt;br /&gt;
* Start up your database server:&lt;br /&gt;
 invoke-rc.d mysql start&lt;br /&gt;
* Check the working of your MySQL server:&lt;br /&gt;
** issue the following command to get status information (to see if MySQL is running after your start command):&lt;br /&gt;
 invoke-rc.d mysql status&lt;br /&gt;
** look under &#039;&#039;/var/log&#039;&#039; for the default MySQL log files &#039;&#039;mysql.log&#039;&#039; and &#039;&#039;mysql.err&#039;&#039;&lt;br /&gt;
** check your SysLog (standard: &#039;&#039;/var/log/syslog&#039;&#039;) for MySQL error messages, since the default Debian configuration is to log MySQL errors there, rather than in the previously mentioned MySQL logfiles.&lt;br /&gt;
&lt;br /&gt;
== MySQL commands ==&lt;br /&gt;
The following are examples of the most common MySQL commands&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
SELECT User,Host from mysql.user;&lt;br /&gt;
SHOW GRANTS FOR &#039;&amp;lt;user&amp;gt;&#039;@&#039;&amp;lt;host&amp;gt;&#039;;&lt;br /&gt;
GRANT &amp;lt;right&amp;gt;, &amp;lt;right2&amp;gt; ON &amp;lt;database&amp;gt;.* TO &#039;&amp;lt;user&amp;gt;&#039;@&#039;&amp;lt;host&amp;gt;&#039;;&lt;br /&gt;
REVOKE &amp;lt;right&amp;gt;, &amp;lt;right2&amp;gt; ON &amp;lt;database&amp;gt;.* FROM &#039;&amp;lt;user&amp;gt;&#039;@&#039;&amp;lt;host&amp;gt;&#039;;&lt;br /&gt;
DROP USER &#039;&amp;lt;user&amp;gt;&#039;@&#039;&amp;lt;host&amp;gt;&#039;;&lt;br /&gt;
SHOW DATABASES;&lt;br /&gt;
USE &amp;lt;database&amp;gt;;&lt;br /&gt;
SHOW TABLES;&lt;br /&gt;
DESCRIBE &amp;lt;table&amp;gt;;&lt;br /&gt;
SELECT &amp;lt;col1&amp;gt;,&amp;lt;col2&amp;gt;...&amp;lt;col_i&amp;gt; FROM &amp;lt;table&amp;gt; WHERE &amp;lt;column&amp;gt; = &#039;&amp;lt;value&amp;gt;&#039;;&lt;br /&gt;
INSERT INTO &amp;lt;table&amp;gt; (&amp;lt;col1&amp;gt;,&amp;lt;col2&amp;gt;...&amp;lt;col_i&amp;gt;) VALUES (&#039;&amp;lt;val1&amp;gt;&#039;,&#039;&amp;lt;val2&amp;gt;&#039;...&#039;&amp;lt;val_i&amp;gt;&#039;);&lt;br /&gt;
UPDATE &amp;lt;table&amp;gt; set &amp;lt;col1&amp;gt; = &#039;&amp;lt;value1&amp;gt;&#039; WHERE &amp;lt;column&amp;gt; = &#039;&amp;lt;value&amp;gt;&#039;;&lt;br /&gt;
DELETE FROM &amp;lt;table&amp;gt; WHERE &amp;lt;column&amp;gt; = &#039;&amp;lt;value&amp;gt;&#039;;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ofcourse there are more useful commands, see the MySQL website.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Talk:Main_Page&amp;diff=3056</id>
		<title>Talk:Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Talk:Main_Page&amp;diff=3056"/>
		<updated>2013-05-11T13:14:38Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: Reverted edits by 216.154.70.149 (talk) to last revision by Saruman!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;You are most welcome to discuss this wiki, but please keep the discussion relevant --[[User:Saruman!|Saruman!]] 10:02, 29 March 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=SaruWiki_talk:Current_events&amp;diff=2746</id>
		<title>SaruWiki talk:Current events</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=SaruWiki_talk:Current_events&amp;diff=2746"/>
		<updated>2012-10-03T17:58:26Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: aw&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;hello m8 my antivirus maybe dont allow me to see all stuff in ur server ..should i login ? register?&lt;br /&gt;
: Heya, antivirus shouldn&#039;t block any content. Also, logging in won&#039;t allow you to see more, only to post without captcha. Maybe your browser blocks Javascript? The MediaWiki software uses some of that... By the way, there&#039;s not much more on this site than this wiki that records Linux bits&#039;n&#039;bobs... --[[User:Saruman!|Saruman!]] 19:58, 3 October 2012 (CEST)&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Creating_digital_certificates_with_our_root_certificate&amp;diff=2744</id>
		<title>Creating digital certificates with our root certificate</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Creating_digital_certificates_with_our_root_certificate&amp;diff=2744"/>
		<updated>2012-08-16T09:33:33Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: /* CA.sh - certificate creation made easy */  typo&amp;#039;s&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Preparing for certificate creation==&lt;br /&gt;
When we&#039;re going to create certificates, we&#039;re going to use the &#039;&#039;openssl&#039;&#039; command twice:&lt;br /&gt;
* once to create a &amp;quot;certificate signing request&amp;quot;, in which we define all information to be included in the certificate, and actually generate the public and private key parts of the key pair, and&lt;br /&gt;
* once to instruct the OpenSSL package to sign the certificate with our CA root certificate.&lt;br /&gt;
The first step thus &#039;&#039;&#039;creates&#039;&#039;&#039; the actual keypair, and the second step &#039;&#039;&#039;signs&#039;&#039;&#039; the public key.&lt;br /&gt;
&lt;br /&gt;
However, we&#039;re going to need to input a lot of parameters on the &#039;&#039;openssl&#039;&#039; command line. We can make things a bit easier for us by specifying these in the &#039;&#039;openssl.cnf&#039;&#039; file, just as we have added some values when creating the CA itself. To be precise, we&#039;re going to add &#039;&#039;&#039;X.509 V3 extensions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default OpenSSL generates V1 certificates, but if we&#039;re not extremely worried about offending certain ancient web browsers, we can add V3 extensions, and even make &#039;&#039;openssl&#039;&#039; do that by default. To do this, we find in &#039;&#039;/etc/ssl/openssl.cnf&#039;&#039; the following line in the section &#039;&#039;[ req ]&#039;&#039;, which is likely present but commented out:&lt;br /&gt;
 req_extensions = v3_req # The extensions to add to a certificate request&lt;br /&gt;
Simply remove the # sign in front of it, so that it appears as given above. This by default enables V3 extensions.&lt;br /&gt;
&lt;br /&gt;
Furthermore, check the section &#039;&#039;[ v3_req ]&#039;&#039;. It should look like this:&lt;br /&gt;
 [ v3_req ]&lt;br /&gt;
 &lt;br /&gt;
 # Extensions to add to a certificate request&lt;br /&gt;
 &lt;br /&gt;
 basicConstraints = CA:FALSE&lt;br /&gt;
 keyUsage = nonRepudiation, digitalSignature, keyEncipherment&lt;br /&gt;
 subjectKeyIdentifier = hash&lt;br /&gt;
What is added is the last line, with &#039;&#039;subjectKeyIdentifier&#039;&#039;; this line specifies how to identify the public key being certified, so that distinct keys used by the same subject can be differentiated (e.g. as key updating occurs, for example). Four values are possible, but the IETF Public Key Infrastructure (PKIX) working group recommends the setting &#039;&#039;subjectKeyIdentifier=hash&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Creating an SSL certificate==&lt;br /&gt;
Now we can create an SSL certificate for a web server. For the Common Name of the certificate, we need the &#039;&#039;&#039;exact&#039;&#039;&#039; name of the web server that&#039;ll offer the SSL connections. However, some servers run different websites as Virtual Hosts, so they could be running, for example, www.saruman.biz, as well as shop.saruman.biz. That might present a problem, because if the certificate is issued for www.saruman.biz, then each visitor of shop.saruman.biz will get a warning along the lines of &amp;quot;Warning: The website you&#039;re trying to visit is shop.saruman.biz, but the certificate offered is for www.saruman.biz&amp;quot;. To prevent that, we could use the wildcard character in the name of the certificate, so as to generate a certificate for *.saruman.biz.&lt;br /&gt;
&lt;br /&gt;
=== CA.sh - certificate creation made easy===&lt;br /&gt;
Since we have the &#039;&#039;openssl.cnf&#039;&#039; set up just right, and the &#039;&#039;CA.sh&#039;&#039; script primed, generating an SSL certificate is not very hard. From any old directory, run as root&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newreq&lt;br /&gt;
This will create the signing request. The questions it&#039;ll ask, are&lt;br /&gt;
* a PEM passphrase, with which to protect the private key of the key pair. Note: you cannot generate a signing request without passphrase, so the private key you&#039;ll generate will &#039;&#039;always&#039;&#039; have a passphrase. If this is not what you want, do not despair: you can easily remove the passphrase from the private key after it&#039;s been generated (see further down). So just use a passphrase, even if you don&#039;t need one.&lt;br /&gt;
* Country/State/Locality/Organization/Organizational Unit; just as with the CA root certificate creation, these have your preprogrammed defaults that you may or may not change.&lt;br /&gt;
* Common Name; here we MUST give the DNS name of the host that is going to use the certificate, e.g. &#039;&#039;shop.saruman.biz&#039;&#039;, or &#039;&#039;*.saruman.biz&#039;&#039;.&lt;br /&gt;
* Challenge password; leave it blank, it&#039;s just to protect your signing request while en-route to the CA - but that&#039;s you anyway :-)&lt;br /&gt;
* Optional company name; leave that blank too, it&#039;s also extra information for the CA.&lt;br /&gt;
&lt;br /&gt;
Now your private key and your certificate signing request (CSR) are ready; they&#039;re called &#039;&#039;newkey.pem&#039;&#039; and &#039;&#039;newreq.pem&#039;&#039; by default, and are located in your working directory. Time to do some signing! From that same working directory, run&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -sign&lt;br /&gt;
The script will show that it&#039;s using the config file &#039;&#039;/usr/lib/ssl/openssl.cnf&#039;&#039; (as we indeed wish), and then ask for the super-duper-secret passphrase to the CA private key (provided you&#039;ve left that in directory &#039;&#039;/etc/ssl/ca/private&#039;&#039;). Feed the script the passphrase, and it&#039;ll get to work. It&#039;ll check the request, then show you the details of the certificate you&#039;re about to sign. An example would be&lt;br /&gt;
 Certificate Details:&lt;br /&gt;
         Serial Number: 1 (0x1)&lt;br /&gt;
         Validity&lt;br /&gt;
             Not Before: Oct 27 09:34:00 2008 GMT&lt;br /&gt;
             Not After : Nov  1 09:34:00 2009 GMT&lt;br /&gt;
         Subject:&lt;br /&gt;
             countryName               = NL&lt;br /&gt;
             stateOrProvinceName       = Utrecht&lt;br /&gt;
             organizationName          = Saruman.biz&lt;br /&gt;
             organizationalUnitName    = Internet Dept.&lt;br /&gt;
             commonName                = shop.saruman.biz&lt;br /&gt;
             emailAddress              = webmaster@saruman.biz&lt;br /&gt;
         X509v3 extensions:&lt;br /&gt;
             X509v3 Basic Constraints:&lt;br /&gt;
                 CA:FALSE&lt;br /&gt;
             Netscape Comment:&lt;br /&gt;
                 OpenSSL Generated Certificate&lt;br /&gt;
             X509v3 Subject Key Identifier:&lt;br /&gt;
                 30:F2:61:80:AA:CF:1B:F0:3E:44:41:D6:38:CC:31:F0:94:28:BD:2B&lt;br /&gt;
             X509v3 Authority Key Identifier:&lt;br /&gt;
                 keyid:80:41:F8:A5:1F:C2:27:6E:CF:A9:28:8E:8A:EF:83:E7:FD:8A:D5:26&lt;br /&gt;
 &lt;br /&gt;
 Certificate is to be certified until Nov  1 09:34:00 2009 GMT (370 days)&lt;br /&gt;
 Sign the certificate? [y/n]:&lt;br /&gt;
After doing your CA duty and diligently checking all the data, just press &#039;&#039;y&#039;&#039;. The script certifies the request, and asks if it is to commit the request. This means it&#039;ll update it&#039;s own database, by saving a copy of the signed certificate in &#039;&#039;/etc/ssl/ca/newcerts&#039;&#039; named after its serial number (&#039;&#039;01.pem&#039;&#039; for this example). Furthermore the script will record the serial and ID&#039;s of the generated certificate so that the next certificate will have a new serial number. And now: hey presto! We have a &#039;&#039;newcert.pem&#039;&#039; in our working directory!&lt;br /&gt;
&lt;br /&gt;
For good measure:&lt;br /&gt;
* delete &#039;&#039;newreq.pem&#039;&#039;&lt;br /&gt;
* rename the generated private key &#039;&#039;newkey.pem&#039;&#039; to &#039;&#039;shop.saruman.biz.seckey.pem&#039;&#039;&lt;br /&gt;
* rename the generated public certificate &#039;&#039;newcert.pem&#039;&#039; to &#039;&#039;shop.saruman.biz.pem&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To remove the passphrase from the private key, use a command like this:&lt;br /&gt;
 openssl rsa -in shop.saruman.biz.seckey.pem -out shop.saruman.biz.nokey.pem&lt;br /&gt;
This will make &#039;&#039;openssl&#039;&#039; ask for your passphrase, and then create the unsecured &#039;&#039;shop.saruman.biz.nokey.pem&#039;&#039; key file. Best practice: ALWAYS use a passphrase-protected key, unless the application cannot support it (e.g. Postfix).&lt;br /&gt;
&lt;br /&gt;
Save the secure private key and its PEM passphrase in a safe place (e.g. Keepass database). And if you removed the passphrase from the private key, then store it in an even safer place!&lt;br /&gt;
&lt;br /&gt;
Now you can deploy your certificate. (more on that in another section).&lt;br /&gt;
&lt;br /&gt;
=== openssl - the hard way to certificate creation===&lt;br /&gt;
We don&#039;t actually need to use the &#039;&#039;CA.sh&#039;&#039; script, because we can do manually what the &#039;&#039;CA.sh&#039;&#039; script does. That gives us more control, but also more work. Let&#039;s see what we&#039;ve got to do.&lt;br /&gt;
&lt;br /&gt;
We will now perform the first step in our &amp;quot;manual&amp;quot; certificate generation: we create a signing request with all the information that we want in our SSL certificate. We run the magic incantation - note how we already&lt;br /&gt;
 openssl req -new -nodes -keyout webmail.saruman.biz.key.pem -out webmail.saruman.biz.req.pem&lt;br /&gt;
This generates a new private key (named &#039;&#039;webmail.saruman.biz.key.pem&#039;&#039;), and a new, non-encrypted (because of &#039;&#039;-nodes&#039;&#039;), key signing request named &#039;&#039;webmail.saruman.biz.req.pem&#039;&#039;. We can leave out terms like &#039;&#039;-newkey rsa:2048&#039;&#039; and &#039;&#039;-days 370&#039;&#039; since we&#039;ve put that in the configuration file. And naturally you&#039;re free to choose your own names for the keys.&lt;br /&gt;
&lt;br /&gt;
FIXME - need the full process here&lt;br /&gt;
&lt;br /&gt;
=== Validating the generated certificates===&lt;br /&gt;
Again, we can use the &#039;&#039;openssl&#039;&#039; command to validate the keys we&#039;ve generated. For instance, the &#039;&#039;CA.sh&#039;&#039; generated certificate, after renaming, is verified with&lt;br /&gt;
 openssl x509 -in shop.saruman.biz.pem -noout -purpose&lt;br /&gt;
 Certificate purposes:&lt;br /&gt;
 SSL client : Yes&lt;br /&gt;
 SSL client CA : No&lt;br /&gt;
 SSL server : Yes&lt;br /&gt;
 SSL server CA : No&lt;br /&gt;
 Netscape SSL server : Yes&lt;br /&gt;
 Netscape SSL server CA : No&lt;br /&gt;
 S/MIME signing : Yes&lt;br /&gt;
 S/MIME signing CA : No&lt;br /&gt;
 S/MIME encryption : Yes&lt;br /&gt;
 S/MIME encryption CA : No&lt;br /&gt;
 CRL signing : Yes&lt;br /&gt;
 CRL signing CA : No&lt;br /&gt;
 Any Purpose : Yes&lt;br /&gt;
 Any Purpose CA : Yes&lt;br /&gt;
 OCSP helper : Yes&lt;br /&gt;
 OCSP helper CA : No&lt;br /&gt;
Notice that the certificate is valid for everything except CA tasks.&lt;br /&gt;
&lt;br /&gt;
Likewise, using &#039;&#039;-dates&#039;&#039; instead of &#039;&#039;-purpose&#039;&#039; lets you see the validity time period, and &#039;&#039;-text&#039;&#039; gives the whole text of the certificate. Note the line marked &amp;quot;issuer&amp;quot;, and see how your own CA is referenced there.&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2743</id>
		<title>DLNA server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2743"/>
		<updated>2012-08-05T17:46:02Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Target of this section of the wiki is to explain how to install and configure your Debian server so that it can act as a multimedia repository for your DLNA-capable equipment. In this case, we&#039;re going to optimize our DLNA server for a Samsung SmartTV, which supports Samsung&#039;s &amp;quot;AllShare&amp;quot;, a slightly extended variant of DLNA.&lt;br /&gt;
==Compiling and installing==&lt;br /&gt;
We start out by downloading the latest version of MiniDLNA from its [http://sourceforge.net/projects/minidlna/files/ SourceForge website]. At the time of writing, it&#039;s version 1.0.25. This file is extracted to the &#039;&#039;&#039;/usr/src/&#039;&#039;&#039; directory:&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;&#039;tar xzf minidlna_1.0.25_src.tar.gz&#039;&#039;&#039;&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;&#039;cd minidlna-1.0.25/&#039;&#039;&#039;&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;&#039;make&#039;&#039;&#039;&lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 &lt;br /&gt;
 ERROR!  Cannot continue.&lt;br /&gt;
 The following required libraries are either missing, or are missing development headers:&lt;br /&gt;
 &lt;br /&gt;
 libavcodec libavformat libavutil libflac libvorbis libogg libid3tag libexif libjpeg&lt;br /&gt;
 &lt;br /&gt;
 make: *** [config.h] Error 1&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
MiniDLNA has some dependencies; executing the &#039;&#039;make&#039;&#039; command has shown us which dependencies are unfulfilled (your list will probably differ). In the above case, the cure for the missing libraries is&lt;br /&gt;
 &#039;&#039;localhost:/usr/src# &#039;&#039;&#039;apt-get install libavcodec-dev libavformat-dev libflac-dev libvorbis-dev libexif-dev libjpeg-dev libid3tag0-dev&#039;&#039;&#039; &#039;&#039;&lt;br /&gt;
After installing all packages that MiniDLNA needs, the output of &#039;&#039;make&#039;&#039; may be similar to:&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;make&#039;&#039;&#039; &lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 Compiling minidlna.c&lt;br /&gt;
 Compiling upnphttp.c&lt;br /&gt;
 Compiling upnpdescgen.c&lt;br /&gt;
 Compiling upnpsoap.c&lt;br /&gt;
 Compiling upnpreplyparse.c&lt;br /&gt;
 Compiling minixml.c&lt;br /&gt;
 Compiling getifaddr.c&lt;br /&gt;
 Compiling daemonize.c&lt;br /&gt;
 Compiling upnpglobalvars.c&lt;br /&gt;
 Compiling options.c&lt;br /&gt;
 Compiling minissdp.c&lt;br /&gt;
 Compiling uuid.c&lt;br /&gt;
 Compiling upnpevents.c&lt;br /&gt;
 Compiling sql.c&lt;br /&gt;
 Compiling utils.c&lt;br /&gt;
 Compiling metadata.c&lt;br /&gt;
 Compiling scanner.c&lt;br /&gt;
 scanner.c: In function âinsert_containersâ:&lt;br /&gt;
 scanner.c:172: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:195: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:207: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:276: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:281: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:297: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:318: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:323: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:338: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 Compiling inotify.c&lt;br /&gt;
 Compiling tivo_utils.c&lt;br /&gt;
 Compiling tivo_beacon.c&lt;br /&gt;
 Compiling tivo_commands.c&lt;br /&gt;
 Compiling tagutils/textutils.c&lt;br /&gt;
 Compiling tagutils/misc.c&lt;br /&gt;
 Compiling tagutils/tagutils.c&lt;br /&gt;
 Compiling playlist.c&lt;br /&gt;
 Compiling image_utils.c&lt;br /&gt;
 Compiling albumart.c&lt;br /&gt;
 Compiling log.c&lt;br /&gt;
 Linking minidlna&lt;br /&gt;
 Compiling testupnpdescgen.c&lt;br /&gt;
 Linking testupnpdescgen&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
After succesful compilation, we can simply install with&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;make install&#039;&#039;&#039;&lt;br /&gt;
 install -d /usr/sbin&lt;br /&gt;
 install minidlna /usr/sbin&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
==Starting MiniDLNA==&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2742</id>
		<title>DLNA server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2742"/>
		<updated>2012-08-05T15:54:14Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Target of this section of the wiki is to explain how to install and configure your Debian server so that it can act as a multimedia repository for your DLNA-capable equipment. In this case, we&#039;re going to optimize our DLNA server for a Samsung SmartTV, which supports Samsung&#039;s &amp;quot;AllShare&amp;quot;, a slightly extended variant of DLNA.&lt;br /&gt;
&lt;br /&gt;
We start out by downloading the latest version of MiniDLNA from its [http://sourceforge.net/projects/minidlna/files/ SourceForge website]. At the time of writing, it&#039;s version 1.0.25. This file is extracted to the &#039;&#039;&#039;/usr/src/&#039;&#039;&#039; directory:&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;&#039;tar xzf minidlna_1.0.25_src.tar.gz&#039;&#039;&#039;&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;&#039;cd minidlna-1.0.25/&#039;&#039;&#039;&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;&#039;make&#039;&#039;&#039;&lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 &lt;br /&gt;
 ERROR!  Cannot continue.&lt;br /&gt;
 The following required libraries are either missing, or are missing development headers:&lt;br /&gt;
 &lt;br /&gt;
 libavcodec libavformat libavutil libflac libvorbis libogg libid3tag libexif libjpeg&lt;br /&gt;
 &lt;br /&gt;
 make: *** [config.h] Error 1&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;br /&gt;
MiniDLNA has some dependencies; executing the &#039;&#039;make&#039;&#039; command has shown us which dependencies are unfulfilled (your list will probably differ). In the above case, the cure for the missing libraries is&lt;br /&gt;
 &#039;&#039;localhost:/usr/src# &#039;&#039;&#039;apt-get install libavcodec-dev libavformat-dev libflac-dev libvorbis-dev libexif-dev libjpeg-dev libid3tag0-dev&#039;&#039;&#039; &#039;&#039;&lt;br /&gt;
After installing all packages that MiniDLNA needs, the output of &#039;&#039;make&#039;&#039; may be similar to:&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;make&#039;&#039;&#039; &lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 Compiling minidlna.c&lt;br /&gt;
 Compiling upnphttp.c&lt;br /&gt;
 Compiling upnpdescgen.c&lt;br /&gt;
 Compiling upnpsoap.c&lt;br /&gt;
 Compiling upnpreplyparse.c&lt;br /&gt;
 Compiling minixml.c&lt;br /&gt;
 Compiling getifaddr.c&lt;br /&gt;
 Compiling daemonize.c&lt;br /&gt;
 Compiling upnpglobalvars.c&lt;br /&gt;
 Compiling options.c&lt;br /&gt;
 Compiling minissdp.c&lt;br /&gt;
 Compiling uuid.c&lt;br /&gt;
 Compiling upnpevents.c&lt;br /&gt;
 Compiling sql.c&lt;br /&gt;
 Compiling utils.c&lt;br /&gt;
 Compiling metadata.c&lt;br /&gt;
 Compiling scanner.c&lt;br /&gt;
 scanner.c: In function âinsert_containersâ:&lt;br /&gt;
 scanner.c:172: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:195: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:207: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:276: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:281: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:297: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:318: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:323: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:338: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 Compiling inotify.c&lt;br /&gt;
 Compiling tivo_utils.c&lt;br /&gt;
 Compiling tivo_beacon.c&lt;br /&gt;
 Compiling tivo_commands.c&lt;br /&gt;
 Compiling tagutils/textutils.c&lt;br /&gt;
 Compiling tagutils/misc.c&lt;br /&gt;
 Compiling tagutils/tagutils.c&lt;br /&gt;
 Compiling playlist.c&lt;br /&gt;
 Compiling image_utils.c&lt;br /&gt;
 Compiling albumart.c&lt;br /&gt;
 Compiling log.c&lt;br /&gt;
 Linking minidlna&lt;br /&gt;
 Compiling testupnpdescgen.c&lt;br /&gt;
 Linking testupnpdescgen&lt;br /&gt;
 localhost:/usr/src/minidlna-1.0.25# &#039;&#039;&#039;_&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2741</id>
		<title>DLNA server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2741"/>
		<updated>2012-08-05T15:51:05Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Target of this section of the wiki is to explain how to install and configure your Debian server so that it can act as a multimedia repository for your DLNA-capable equipment. In this case, we&#039;re going to optimize our DLNA server for a Samsung SmartTV, which supports Samsung&#039;s &amp;quot;AllShare&amp;quot;, a slightly extended variant of DLNA.&lt;br /&gt;
&lt;br /&gt;
We start out by downloading the latest version of MiniDLNA from its [http://sourceforge.net/projects/minidlna/files/ SourceForge website]. At the time of writing, it&#039;s version 1.0.25. This file is extracted to the &#039;&#039;&#039;/usr/src/&#039;&#039;&#039; directory:&lt;br /&gt;
 &#039;&#039;&#039;localhost:/usr/src# &#039;&#039;tar xzf minidlna_1.0.25_src.tar.gz&#039;&#039;&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;cd minidlna-1.0.25/&#039;&#039;&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;make&#039;&#039;&lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 &lt;br /&gt;
 ERROR!  Cannot continue.&lt;br /&gt;
 The following required libraries are either missing, or are missing development headers:&lt;br /&gt;
 &lt;br /&gt;
 libavcodec libavformat libavutil libflac libvorbis libogg libid3tag libexif libjpeg&lt;br /&gt;
 &lt;br /&gt;
 make: *** [config.h] Error 1&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;_&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
MiniDLNA has some dependencies; executing the &#039;&#039;&#039;make&#039;&#039;&#039; command has shown us which dependencies are unfulfilled (your list will probably differ). In the above case, the cure for the missing libraries is&lt;br /&gt;
 &#039;&#039;&#039;localhost:/usr/src# &#039;&#039;apt-get install libavcodec-dev libavformat-dev libflac-dev libvorbis-dev libexif-dev libjpeg-dev libid3tag0-dev&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
After installing all packages that MiniDLNA needs, the output of &#039;&#039;&#039;make&#039;&#039;&#039; becomes:&lt;br /&gt;
 &#039;&#039;&#039;dworkin:/usr/src/minidlna-1.0.25# &#039;&#039;make&#039;&#039; &lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 Compiling minidlna.c&lt;br /&gt;
 Compiling upnphttp.c&lt;br /&gt;
 Compiling upnpdescgen.c&lt;br /&gt;
 Compiling upnpsoap.c&lt;br /&gt;
 Compiling upnpreplyparse.c&lt;br /&gt;
 Compiling minixml.c&lt;br /&gt;
 Compiling getifaddr.c&lt;br /&gt;
 Compiling daemonize.c&lt;br /&gt;
 Compiling upnpglobalvars.c&lt;br /&gt;
 Compiling options.c&lt;br /&gt;
 Compiling minissdp.c&lt;br /&gt;
 Compiling uuid.c&lt;br /&gt;
 Compiling upnpevents.c&lt;br /&gt;
 Compiling sql.c&lt;br /&gt;
 Compiling utils.c&lt;br /&gt;
 Compiling metadata.c&lt;br /&gt;
 Compiling scanner.c&lt;br /&gt;
 scanner.c: In function âinsert_containersâ:&lt;br /&gt;
 scanner.c:172: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:195: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:207: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:276: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:281: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:297: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:318: warning: format â%lXâ expects type âlong unsigned intâ, but argument 3 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:323: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 scanner.c:338: warning: format â%lXâ expects type âlong unsigned intâ, but argument 4 has type âsqlite_int64â&lt;br /&gt;
 Compiling inotify.c&lt;br /&gt;
 Compiling tivo_utils.c&lt;br /&gt;
 Compiling tivo_beacon.c&lt;br /&gt;
 Compiling tivo_commands.c&lt;br /&gt;
 Compiling tagutils/textutils.c&lt;br /&gt;
 Compiling tagutils/misc.c&lt;br /&gt;
 Compiling tagutils/tagutils.c&lt;br /&gt;
 Compiling playlist.c&lt;br /&gt;
 Compiling image_utils.c&lt;br /&gt;
 Compiling albumart.c&lt;br /&gt;
 Compiling log.c&lt;br /&gt;
 Linking minidlna&lt;br /&gt;
 Compiling testupnpdescgen.c&lt;br /&gt;
 Linking testupnpdescgen&lt;br /&gt;
 dworkin:/usr/src/minidlna-1.0.25# &#039;&#039;_&#039;&#039;&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=APT_and_aptitude&amp;diff=2740</id>
		<title>APT and aptitude</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=APT_and_aptitude&amp;diff=2740"/>
		<updated>2012-08-05T15:30:05Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: added apt-file&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Using APT and Aptitude==&lt;br /&gt;
&lt;br /&gt;
Your Debian system can easily be expanded, and also kept up-to-date with the latest security fixes, if you use Debian&#039;s beautiful [http://www.debian.org/doc/manuals/apt-howto/ch1.en.html APT (Advanced Packaging Technology)] tools. Of all available [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT-based tools], we usually use the following:&lt;br /&gt;
* apt-get, the command line utilities that go with APT; or&lt;br /&gt;
* aptitude, a [http://en.wikipedia.org/wiki/Curses_%28programming_library%29 curses-based] frontend for APT.&lt;br /&gt;
&lt;br /&gt;
These APT-based tools are incredibly powerful and flexible, but we&#039;re not going to explain them fully here (for tuturials and whatnot, go [http://www.debian.org/doc/manuals/apt-howto/ here]). What we need to establish now, is how to configure APT, and how to use it.&lt;br /&gt;
&lt;br /&gt;
APT gets its information from a configuration file that can be found in &#039;&#039;/etc/apt&#039;&#039;. Of these, the most important is &#039;&#039;sources.list&#039;&#039; because it defines what packages and updates can be installed from where, and even what version of Debian we want to maintain. For now let&#039;s just suffice to say that in the sources.list, you need to remove the references to the CD-ROm with which you installed the system, and specify which on-line repository you wish to use for installing and updating packages. To this end, open &#039;&#039;/etc/apt/sources.list&#039;&#039; with [[Vim | your favourite text editor]] while you are logged in as root.&lt;br /&gt;
&lt;br /&gt;
References to the CD-ROM look a bit like this:&lt;br /&gt;
 deb cdrom:[Debian GNU/Linux testing _Etch_ - Official Beta i386 CD Binary-1 20070317-21:45]/ etch contrib main&lt;br /&gt;
Disable this line by putting a hash (#) in front of it (you could have more than one line beginning with &#039;&#039;deb cdrom:&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Now make sure you have a section that references one or more on-line repositories. This could make your &#039;&#039;sources.list&#039;&#039; look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# deb cdrom:[Debian GNU/Linux testing _Etch_ - Official Beta i386 CD Binary-1 20070317-21:45]/ etch contrib main&lt;br /&gt;
&lt;br /&gt;
deb ftp://ftp.nl.debian.org/debian/ etch main contrib&lt;br /&gt;
deb-src ftp://ftp.nl.debian.org/debian/ etch main contrib&lt;br /&gt;
&lt;br /&gt;
deb http://security.debian.org/ etch/updates main contrib&lt;br /&gt;
deb-src http://security.debian.org/ etch/updates main contrib&lt;br /&gt;
&lt;br /&gt;
# deb ftp://ftp.nl.debian.org/debian-volatile etch/volatile main contrib&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you want to update, change, add software, or even remove software, you better update your APT system by running one of the following commands:&lt;br /&gt;
* sudo apt-get update&lt;br /&gt;
* sudo aptitude update&lt;br /&gt;
* sudo aptitude, then press &#039;&#039;u&#039;&#039;&lt;br /&gt;
Note: if you haven&#039;t installed [[sudo]] yet, then you can only run the commands as root, and they are then: &#039;&#039;apt-get update&#039;&#039;, &#039;&#039;aptitude update&#039;&#039;, and &#039;&#039;aptitude&#039;&#039; then &#039;&#039;u&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Getting informed on installed packages==&lt;br /&gt;
You might at some time wonder if a package is already installed. Usually, you&#039;d check this using&lt;br /&gt;
 dpkg --get-selections&lt;br /&gt;
The output of this can be rather unwieldy, but you can send the output to a program like &#039;&#039;grep&#039;&#039; to refine your search. As an example: use&lt;br /&gt;
 dpkg --get-selections | grep install -c&lt;br /&gt;
to see just how many packages you have.&lt;br /&gt;
&lt;br /&gt;
But this standard command doesn&#039;t directly concerns itself with versions or installation history.&lt;br /&gt;
&lt;br /&gt;
Now if you&#039;re wondering what version a specific package (or set of packages) is, then you can install package &#039;&#039;apt-show-versions&#039;&#039; and run it on the command line; if you wish to know the version of a particular file, e.g. &#039;&#039;sudo&#039;&#039;, you&#039;d run&lt;br /&gt;
 apt-show-versions sudo&lt;br /&gt;
This package is described on [http://www.debianadmin.com/list-your-installed-package-versions-with-apt-show-versions.html Debian Admin]. It can do much more, but there&#039;s a fine &#039;&#039;man&#039;&#039; page for that.&lt;br /&gt;
&lt;br /&gt;
Furthermore, if you&#039;re interested in the installation history of your packages, you could check out the &#039;&#039;dpkg&#039;&#039; log file, by default &#039;&#039;/var/log/dpkg.log&#039;&#039;. This logging file/location is set in &#039;&#039;/etc/dpkg/dpkg.cfg&#039;&#039;. So to find the installation time/date of all programs, you could execute&lt;br /&gt;
 grep &amp;quot;status installed&amp;quot; /var/log/dpkg.log&lt;br /&gt;
&lt;br /&gt;
==Getting information on packages that are NOT installed==&lt;br /&gt;
This can be done with a package named &#039;&#039;&#039;apt-file&#039;&#039;&#039;. More information [http://www.debianhelp.co.uk/findfile.htm here].&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2739</id>
		<title>DLNA server</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=DLNA_server&amp;diff=2739"/>
		<updated>2012-08-05T15:19:01Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: start&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Target of this section of the wiki is to explain how to install and configure your Debian server so that it can act as a multimedia repository for your DLNA-capable equipment. In this case, we&#039;re going to optimize our DLNA server for a Samsung SmartTV, which supports Samsung&#039;s &amp;quot;AllShare&amp;quot;, a slightly extended variant of DLNA.&lt;br /&gt;
&lt;br /&gt;
We start out by downloading the latest version of MiniDLNA from its [http://sourceforge.net/projects/minidlna/files/ SourceForge website]. At the time of writing, it&#039;s version 1.0.25. This file is extracted to the &#039;&#039;&#039;/usr/src/&#039;&#039;&#039; directory:&lt;br /&gt;
 &#039;&#039;&#039;localhost:/usr/src# &#039;&#039;tar xzf minidlna_1.0.25_src.tar.gz&#039;&#039;&lt;br /&gt;
 localhost:/usr/src# &#039;&#039;cd minidlna-1.0.25/&#039;&#039;&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;make&#039;&#039;&lt;br /&gt;
 ./genconfig.sh&lt;br /&gt;
 &lt;br /&gt;
 ERROR!  Cannot continue.&lt;br /&gt;
 The following required libraries are either missing, or are missing development headers:&lt;br /&gt;
 &lt;br /&gt;
 libavcodec libavformat libavutil libflac libvorbis libogg libid3tag libexif libjpeg&lt;br /&gt;
 &lt;br /&gt;
 make: *** [config.h] Error 1&lt;br /&gt;
 localhost:/usr/srcminidlna-1.0.25# &#039;&#039;_&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
MiniDLNA has some dependencies; executing the &#039;&#039;&#039;make&#039;&#039;&#039; command has shown us which dependencies are unfulfilled (your list will probably differ). After installing all packages that MiniDLNA needs, the output of &#039;&#039;&#039;make&#039;&#039;&#039; becomes:&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=2738</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Main_Page&amp;diff=2738"/>
		<updated>2012-08-05T15:11:31Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: dlna&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;Welcome to SaruWiki.&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Wiki is intended to document bits and bobs about [http://www.kernel.org/ Linux] (and some Unix) in general, and [http://www.debian.org Debian] in particular. In it, [[SaruWiki:About|we]] wish to collect the tips and tricks of both [[SaruWiki:About|our own team of Linux admins]] and those of other interested users. If you are interested in my work on [http://www.dya.info DYA|Infrastructure], please visit the [https://dya-knowledge.sogeti.nl/ SmartMart demo site].&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using this wiki&#039;s software.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;NOTE:&amp;lt;/big&amp;gt; &#039;&#039;&#039;you must confirm edits&#039;&#039;&#039; when you&#039;re not logged in with a user account. Thanks to the Mediawiki ConfirmEdit extension we&#039;ve cut our wikispam considerably. Sorry to make you anonymous contributors jump through this little hoop for every edit, but there you are.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;big&amp;gt;&#039;&#039;&#039;Main Content&#039;&#039;&#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setting up a [[Debian Squeeze base server]] is a howto on the installation of a very basic Linux box under Lenny (it&#039;s actually not even a server yet).&lt;br /&gt;
* Using &#039;&#039;md&#039;&#039; for [[software-based RAID]] contains our ideas and observations on redundancy.&lt;br /&gt;
* The use of [[APT and aptitude]] is crucial to the concept of a Debian machine.&lt;br /&gt;
* [[Roll your own kernel]] discusses the pros and cons of compiling your own kernel, and how to do it.&lt;br /&gt;
* [[Essential system software]] lists all (sets of) packages that we deem, well, essential.&lt;br /&gt;
* [[Apache2 and PHP5]] are essential packages if you want to light your own little [[LAMP]].&lt;br /&gt;
* [[Pluggable Authentication Modules (PAM)]] is a great way to secure your server and arrange logins - if you get to understand them&lt;br /&gt;
* [[Certificate fundamentals | The &amp;quot;certificates&amp;quot; section]] explains how you create your own Certificate Authority (CA) and the neat things you can do with it.&lt;br /&gt;
* [[Database 101]] introduces you to MySQL.&lt;br /&gt;
* [[OpenLDAP]] is a rudimentary howto about getting OpenLDAP to be your central user repository.&lt;br /&gt;
* The [[Installing SaMBa with OpenLDAP support | SaMBa section]] explains how to install SaMBa with OpenLDAP as user backend.&lt;br /&gt;
* [[Add an X11 server]] to your server, if you need one.&lt;br /&gt;
* Of course we have a [[e-mail server section]], where we focus on Postfix and virtual mail domains, and add in a whiff of MySQL and OpenLDAP.&lt;br /&gt;
* The [[Asterisk section]] is about all things re: telephony on Debian Lenny.&lt;br /&gt;
* The [[system boot procedure]] section explains what we can customise in the standard ways Debian boots.&lt;br /&gt;
* The [[networking section]] treats subjects like setting persistent routes.&lt;br /&gt;
* The [[firewall section]] is where we discuss &amp;quot;IPtables&amp;quot; (netfilter) and how we use it for firewalling.&lt;br /&gt;
* The [[native IPsec tunnel]] section describes how to configure an IPsec tunnel.&lt;br /&gt;
* [[Hardware monitoring]] is important for your server&#039;s health and reliability.&lt;br /&gt;
* [[Vmware_server|VMware Server basics]] gives some pointers on how to install VMware Server on a Debian server box.&lt;br /&gt;
* Make your server a [[Microsoft PPTP server | Microsoft client compatible VPN Server ]].&lt;br /&gt;
* Creating a [[backup]] for your server.&lt;br /&gt;
* How to install [[Mediawiki Installation | Mediawiki]] on your Debian server - like what you&#039;re looking at now.&lt;br /&gt;
* How to [[DLNA server|create your own multimedia server]], supporting [http://www.dlna.org/ DLNA] (which is [http://hometheater.about.com/od/interactivetelevision/a/Samsung-Allshare-Media-Streaming-basics-bg.htm Samsung&#039;s &amp;quot;AllShare&amp;quot;])&lt;br /&gt;
If you&#039;d like to create a new page, please log in and go ahead:&lt;br /&gt;
&amp;lt;inputbox&amp;gt;&lt;br /&gt;
type=create&lt;br /&gt;
&amp;lt;/inputbox&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: the Wiki admins reserve the right to edit or remove any content they feel is not suitable for this site, not relevant, (too) inaccurate or otherwise not in line with the intentions and spirit of the admin team.&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;websiteFrame&amp;gt;&lt;br /&gt;
website=http://www.google.com/talk/service/badge/Show?tk&amp;amp;#61;z01q6amlqld8jocej2ca891jl9dunqqra83nhehaoqpednb5skkur0fv70jsuavce4ii9ms5e9afdr8qmpsc1d9upni4jom8g1em3p1cvq1p5eo1ugv162fosgprdv867iuememlcogfle8n3dmcf97durjld85avnh8k5lm1&amp;amp;amp;w=200&amp;amp;amp;h=60 &lt;br /&gt;
border=0&lt;br /&gt;
height=60&lt;br /&gt;
width=200&lt;br /&gt;
name=GoogleChatwithSaruman!&lt;br /&gt;
allowtransparency=true&lt;br /&gt;
&amp;lt;/websiteFrame&amp;gt;&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Talk:IPsec_tunneling_diagnostics&amp;diff=2734</id>
		<title>Talk:IPsec tunneling diagnostics</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Talk:IPsec_tunneling_diagnostics&amp;diff=2734"/>
		<updated>2012-07-11T18:05:37Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here&#039;s a specific tip for diagnosing ipsec tunnel difficulties. If nothing is happening -- the tunnel doesn&#039;t seem to be activating, and there isn&#039;t any output about it at all -- it&#039;s probable that your security policy configuration is incorrect, so nothing is even trying to use the tunnel. In my case, I got the direction of the traffic mixed up, and tried to say &amp;quot;inbound traffic from myself to machine XYZ should go through the tunnel&amp;quot; (and vice versa). Since I was just working with IP addresses, it was really easy to get them backwards and not notice that fact without a rigorous inspection. Once I reversed the direction and was able to get some output in my logs, my other issues were much easier to identify. :)&lt;br /&gt;
&lt;br /&gt;
Here&#039;s my other specific tip. Output like &amp;quot;ERROR: phase1 negotiation failed due to time up.&amp;quot; may mean &amp;quot;check your firewalls, you&#039;re probably blocking the port. and then when you&#039;re done, check your OTHER firewall.&amp;quot; (If you&#039;re on Amazon EC2, that means to check your security groups, including (if you&#039;re in a VPC) both inbound and outbound rules, and subnet ACLs.&lt;br /&gt;
&lt;br /&gt;
-- [[Special:Contributions/174.62.124.8|174.62.124.8]] 23:48, 8 July 2012 (CEST)&lt;br /&gt;
: Good tips! Thanks, --[[User:Saruman!|Saruman!]] 20:05, 11 July 2012 (CEST)&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=APT_and_aptitude&amp;diff=2732</id>
		<title>APT and aptitude</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=APT_and_aptitude&amp;diff=2732"/>
		<updated>2012-05-27T08:35:23Z</updated>

		<summary type="html">&lt;p&gt;Saruman!: added inform.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Using APT and Aptitude==&lt;br /&gt;
&lt;br /&gt;
Your Debian system can easily be expanded, and also kept up-to-date with the latest security fixes, if you use Debian&#039;s beautiful [http://www.debian.org/doc/manuals/apt-howto/ch1.en.html APT (Advanced Packaging Technology)] tools. Of all available [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT-based tools], we usually use the following:&lt;br /&gt;
* apt-get, the command line utilities that go with APT; or&lt;br /&gt;
* aptitude, a [http://en.wikipedia.org/wiki/Curses_%28programming_library%29 curses-based] frontend for APT.&lt;br /&gt;
&lt;br /&gt;
These APT-based tools are incredibly powerful and flexible, but we&#039;re not going to explain them fully here (for tuturials and whatnot, go [http://www.debian.org/doc/manuals/apt-howto/ here]). What we need to establish now, is how to configure APT, and how to use it.&lt;br /&gt;
&lt;br /&gt;
APT gets its information from a configuration file that can be found in &#039;&#039;/etc/apt&#039;&#039;. Of these, the most important is &#039;&#039;sources.list&#039;&#039; because it defines what packages and updates can be installed from where, and even what version of Debian we want to maintain. For now let&#039;s just suffice to say that in the sources.list, you need to remove the references to the CD-ROm with which you installed the system, and specify which on-line repository you wish to use for installing and updating packages. To this end, open &#039;&#039;/etc/apt/sources.list&#039;&#039; with [[Vim | your favourite text editor]] while you are logged in as root.&lt;br /&gt;
&lt;br /&gt;
References to the CD-ROM look a bit like this:&lt;br /&gt;
 deb cdrom:[Debian GNU/Linux testing _Etch_ - Official Beta i386 CD Binary-1 20070317-21:45]/ etch contrib main&lt;br /&gt;
Disable this line by putting a hash (#) in front of it (you could have more than one line beginning with &#039;&#039;deb cdrom:&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Now make sure you have a section that references one or more on-line repositories. This could make your &#039;&#039;sources.list&#039;&#039; look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# deb cdrom:[Debian GNU/Linux testing _Etch_ - Official Beta i386 CD Binary-1 20070317-21:45]/ etch contrib main&lt;br /&gt;
&lt;br /&gt;
deb ftp://ftp.nl.debian.org/debian/ etch main contrib&lt;br /&gt;
deb-src ftp://ftp.nl.debian.org/debian/ etch main contrib&lt;br /&gt;
&lt;br /&gt;
deb http://security.debian.org/ etch/updates main contrib&lt;br /&gt;
deb-src http://security.debian.org/ etch/updates main contrib&lt;br /&gt;
&lt;br /&gt;
# deb ftp://ftp.nl.debian.org/debian-volatile etch/volatile main contrib&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you want to update, change, add software, or even remove software, you better update your APT system by running one of the following commands:&lt;br /&gt;
* sudo apt-get update&lt;br /&gt;
* sudo aptitude update&lt;br /&gt;
* sudo aptitude, then press &#039;&#039;u&#039;&#039;&lt;br /&gt;
Note: if you haven&#039;t installed [[sudo]] yet, then you can only run the commands as root, and they are then: &#039;&#039;apt-get update&#039;&#039;, &#039;&#039;aptitude update&#039;&#039;, and &#039;&#039;aptitude&#039;&#039; then &#039;&#039;u&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Getting informed on installed packages==&lt;br /&gt;
You might at some time wonder if a package is already installed. Usually, you&#039;d check this using&lt;br /&gt;
 dpkg --get-selections&lt;br /&gt;
The output of this can be rather unwieldy, but you can send the output to a program like &#039;&#039;grep&#039;&#039; to refine your search. As an example: use&lt;br /&gt;
 dpkg --get-selections | grep install -c&lt;br /&gt;
to see just how many packages you have.&lt;br /&gt;
&lt;br /&gt;
But this standard command doesn&#039;t directly concerns itself with versions or installation history.&lt;br /&gt;
&lt;br /&gt;
Now if you&#039;re wondering what version a specific package (or set of packages) is, then you can install package &#039;&#039;apt-show-versions&#039;&#039; and run it on the command line; if you wish to know the version of a particular file, e.g. &#039;&#039;sudo&#039;&#039;, you&#039;d run&lt;br /&gt;
 apt-show-versions sudo&lt;br /&gt;
This package is described on [http://www.debianadmin.com/list-your-installed-package-versions-with-apt-show-versions.html Debian Admin]. It can do much more, but there&#039;s a fine &#039;&#039;man&#039;&#039; page for that.&lt;br /&gt;
&lt;br /&gt;
Furthermore, if you&#039;re interested in the installation history of your packages, you could check out the &#039;&#039;dpkg&#039;&#039; log file, by default &#039;&#039;/var/log/dpkg.log&#039;&#039;. This logging file/location is set in &#039;&#039;/etc/dpkg/dpkg.cfg&#039;&#039;. So to find the installation time/date of all programs, you could execute&lt;br /&gt;
 grep &amp;quot;status installed&amp;quot; /var/log/dpkg.log&lt;/div&gt;</summary>
		<author><name>Saruman!</name></author>
	</entry>
</feed>