<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Admin Zone &#187; Security</title>
	<atom:link href="http://linuxadminzone.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxadminzone.com</link>
	<description>Adding more reasons to celebrate Open Source.</description>
	<lastBuildDate>Wed, 09 May 2012 10:17:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Ensuring secure access to Production Linux Servers</title>
		<link>http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/</link>
		<comments>http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 06:04:38 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[public/private keys]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=245</guid>
		<description><![CDATA[I was amazed to hear from my friend that one of their server got hacked and reason may be that their part-time admin set password of root user as &#8216;admin&#8217;. Wow!! can&#8217;t believe it! They dont have right to cry about security attacks as they themselves keep their door opens I&#8217;ve suggested them some points [...]]]></description>
			<content:encoded><![CDATA[<p>I was amazed to hear from my friend that one of their server got hacked and reason may be that their part-time admin set password of root user as &#8216;admin&#8217;. Wow!! can&#8217;t believe it! They dont have right to cry about security attacks as they themselves keep their door opens <img src='http://linuxadminzone.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p> I&#8217;ve suggested them some points as per described below for ensuring secure access to servers. They have 5-6 Linux servers. This is obviously may not be the best way and I&#8217;m as always appreciate if you can give your suggestion in comments. My approach is that from 6 servers, we will be able to login only in 2 servers from remote through key based access and from these 2 server, we can access remaining. Here&#8217;s what we did:</p>
<p><strong>1. Disable root access</strong><br />
Completely disable root login access from remote. Period. Open <strong>/etc/ssh/sshd_config</strong> and add/remove comment from this line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi /etc/ssh/sshd_config</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PermitRootLogin no</pre></div></div>

<p><strong>2. Login only through non-root user </strong><br />
Create non-root user and create public/private key pair for it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ adduser loginu</pre></div></div>

<p>login to &#8216;loginu&#8217; user created above, or if you are in root, just su:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># su loginu</span>
$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> dsa</pre></div></div>

<p>Enter details while generating keys, enter good passphares and always remember it. Now you can go ahead and disable password based access completely so user can only login by using keys but this may be too restrictive or problematic for them if they forget passphares etc. if you want to go ahead, make sure these statements are there in /etc/ssh/sshd_config file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #666666; font-style: italic;"># vi /etc/ssh/sshd_config</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PasswordAuthentication no
PubkeyAuthentication <span style="color: #c20cb9; font-weight: bold;">yes</span>
AuthorizedKeysFile      .ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>copy the key you created earlier (there should be two files in ~loginu/.ssh/ directory: id_dsa, id_dsa.pub. so copy id_dsa) to your pc so from next time you can use this key to login into the server. </p>
<p>Just make sure you are able to login through &#8216;loginu&#8217; user before applying these ssh settings. Jump to terminal in your pc and try to login with key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-i</span> id_dsa loginu<span style="color: #000000; font-weight: bold;">@</span>your.server.ip</pre></div></div>

<p>It will ask for passpahres and after supplying it you should be able to login into the server. Please make note that this is very confidential key and store it in good place/directory. Alternatively you can also generate keys in your own pc and store them at server to facilitate login. But if you want flexibility to have only one key (like carry it in your usb stick) and be able to login with it, I found this approach good to use server keys instead of pc keys. </p>
<p><strong>3. (Optional) Restrict login by IPs</strong><br />
Now come back in server. You can further strengthen security by allowing only select IPs to log in:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi /etc/ssh/sshd_config</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">AllowUsers loginu<span style="color: #000000; font-weight: bold;">@</span>aa.aa.aa.aa loginu<span style="color: #000000; font-weight: bold;">@</span>bb.bb.bb.bb loginu<span style="color: #000000; font-weight: bold;">@</span>cc.cc.cc.cc</pre></div></div>

<p>Here replace aa/bb/cc with actual IP addresses from where you want to allow access. </p>
<p>Going ahead, optionally, You can also change port for ssh from default 22 to other by using this <a href="http://linuxadminzone.com/quickly-change-your-ssh-port-from-default-22-to-something-higher/">guide</a> but as I think we are only allowing access through keys and from select remote places only, this you may skip. </p>
<p>Reload sshd daemon to apply settings which you have set in /etc/ssh/sshd_config by:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service sshd reload</span></pre></div></div>

<p>Without closing current login session, try to login again from other terminal to check you are able to login into the server. </p>
<p><strong> 4. Secure other servers </strong><br />
As mentioned earlier, I preferred to treat first 2 server as &#8216;login&#8217; server in which we can login from anywhere using user &#8216;loginu&#8217; with key and then can login to other servers. So effectively other servers would not allow direct access from remote. Jump to server 3-6 and set following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi /etc/ssh/sshd_config</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">AllowUsers loginu<span style="color: #000000; font-weight: bold;">@</span>aa.aa.aa.aa root<span style="color: #000000; font-weight: bold;">@</span>aa.aa.aa.aa loginu<span style="color: #000000; font-weight: bold;">@</span>bb.bb.bb. root<span style="color: #000000; font-weight: bold;">@</span>bb.bb.bb.bb</pre></div></div>

<p>here aa.aa/bb.bb indicates IP address of server #1 and #2 (login servers). So in this (#3) server we can login from those server(s) only. After making changes, reload ssh daemon to apply settings in all of these servers:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># service sshd reload</span></pre></div></div>

<p><strong> 5. Other services </strong><br />
I suggested to disable every service that we don&#8217;t need in servers. That&#8217;s the best approach to secure them <img src='http://linuxadminzone.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . These servers has role of web servers and rsync process is there to sync files. In that case, created another non-root user:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># adduser rsyncuser</span></pre></div></div>

<p>generate keys (you can generate passphares less keys) for this user as well. Create same user in all other servers and put first server&#8217;s (from where rsync initiate) keys in them. Dont allow this user to login from remote but only from server where rsync initiate. I&#8217;ve documented rsync process <a href="http://linuxadminzone.com/script-to-sync-files-between-web-severs-having-plesk/">here</a>, if you want to go ahead and configure it. Similarly, if you need services like FTP then allow this only from selected IP address (by configuring /etc/hosts.allow) or firewall etc.</p>
<p><strong> 6. Configure DenyHosts </strong><br />
To further prevent attacks and block any IP address from which several failed login attempt originated, you should configure DenyHosts script ( I have documented howto on DenyHosts <a href="http://linuxadminzone.com/install-and-configure-denyhost/">here</a>) or equivalent.  </p>
<p>Other Most Read Articles:<br />
*  <a href="http://linuxadminzone.com/top-5-most-useful-commands-tools-for-linux-administrators/">Top 5 Linux commands for Administrators.</a><br />
* <a href="http://linuxadminzone.com/quick-howto-install-and-configure-munin-for-server-monitoring/">Install and configure Munin/Monitor for monitoring. </a><br />
* <a href="http://linuxadminzone.com/change-timezone-in-your-linux-server-quickly/ ">Change time zone in your Linux machine quickly.</a><br />
* <a href="http://linuxadminzone.com/detect-directory-or-file-changes-in-linuxunix/">Detect directory changes in Linux.</a><br />
* <a href="http://linuxadminzone.com/bash-script-to-backup-essential-log-files-of-linux-server/">Script to backup essential log files.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Save root or user history to check later</title>
		<link>http://linuxadminzone.com/save-root-or-user-history-to-check-later/</link>
		<comments>http://linuxadminzone.com/save-root-or-user-history-to-check-later/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 08:18:09 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[root history]]></category>
		<category><![CDATA[user history]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=6</guid>
		<description><![CDATA[Some times we need a way to automatically save any user&#8217;s or root&#8217;s activity so that we can check later. In environment, where root account is accessible by multiple people, its very helpful to exactly know who did what and when? In my case, I have found that some files are changed mysteriously but I [...]]]></description>
			<content:encoded><![CDATA[<p>Some times we need a way to automatically save any user&#8217;s or root&#8217;s activity so that we can check later. In environment, where root account is accessible by multiple people, its very helpful to exactly know who did what and when? In my case, I have found that some files are changed mysteriously but I was clueless as there are more than one users with root access.</p>
<p>To save the activity/history of any user (including root), you need to open the user&#8217;s .bash_profile from his home directory.</p>
<p>Here, for instance, I would like to record all commands in a file when a user login as root or su to root. History will be stored in a file with name as DateTimeIPAddress from where user came.</p>
<p>Step 1. Go to root&#8217;s home:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~</pre></div></div>

<p>Step 2. You can make a hidden directory so that all history files will be stored there:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> .rhistdata</pre></div></div>

<p>Step 3. Open .bash_profile and write down following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vi</span> .bash_profile
<span style="color: #666666; font-style: italic;"># save root history</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">3000</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">5000</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.rhistdata<span style="color: #000000; font-weight: bold;">/</span>.bash_hist-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">who</span> am i <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3.$4.$5.$6}'</span>;<span style="color: #7a0874; font-weight: bold;">exit</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Save and close the file.</p>
<p>It&#8217;s simple. You can try to login again as root, do something and logout. Login again and check that there&#8217;s file having all commands you performed.</p>
<p>* <a href="http://linuxadminzone.com/5-steps-to-secure-your-linux-server/"> 5 steps to secure your Linux Server </a><br />
* <a href="http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/"> Ensuring secure access to production Linux Servers </a><br />
* <a href="http://linuxadminzone.com/bash-script-to-backup-essential-log-files-of-linux-server/"> Bash script to backup essential log files in Linux </a><br />
* <a href="http://linuxadminzone.com/quickly-change-your-ssh-port-from-default-22-to-something-higher/"> Quickly change your ssh port from defualt 22 to something higher </a><br />
* <a href="http://linuxadminzone.com/ssh-port-forwarding-from-remote-to-local-machine/"> SSH port forwarding from remote to local machine </a><br />
* <a href="http://linuxadminzone.com/install-and-configure-denyhost/"> Install and configure denyhost to prevent brute force attacks </a></p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/save-root-or-user-history-to-check-later/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install and configure DenyHost</title>
		<link>http://linuxadminzone.com/install-and-configure-denyhost/</link>
		<comments>http://linuxadminzone.com/install-and-configure-denyhost/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 13:24:56 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[DenyHost]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=5</guid>
		<description><![CDATA[Brute force attacks or dictionary based attacks are common these days for servers. DenyHosts is an excellent python tool to prevent such attacks. It will detects failed attempts and prevent offending Host/IP for further connection by adding it to /etc/hosts.deny file. Here are steps to install and configure DenyHosts for your server. These steps are [...]]]></description>
			<content:encoded><![CDATA[<p>Brute force attacks or dictionary based attacks are common these days for servers. DenyHosts is an excellent python tool to prevent such attacks. It will detects failed attempts and prevent offending Host/IP for further connection by adding it to <strong>/etc/hosts.deny</strong> file.</p>
<p>Here are steps to install and configure DenyHosts for your server. These steps are applicable for Red Hat based distros (ie RHEL, CentOS, Fedora) and needs minor changes for other distros. You can copy paste the commands.</p>
<p><strong>Step 1.</strong> Detect which version of Python is installed on your server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># python -V</span></pre></div></div>

<p><strong>Step 2.</strong> You will see python version 2.3.x (for CentOS 4.x) or 2.4.x (,CentOS 5.x, Fedora etc). Download the relevant rpm from <a href="http://sourceforge.net/project/showfiles.php?group_id=131204">sourceforge</a> or source tarball, I have download it by using this direct <a href="wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fdenyhosts%2Ffiles%2F&#038;ts=1297618714&#038;use_mirror=space">link</a>.</p>
<p><strong>Step 3.</strong> Install the rpm:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># rpm -ivh DenyHosts-2.6-python2.3.noarch.rpm</span></pre></div></div>

<p>or compile and install from tarball, you have it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># tar xzf DenyHosts-2.6.tar.gz</span>
<span style="color: #666666; font-style: italic;"># cd DenyHosts-2.6 </span>
<span style="color: #666666; font-style: italic;"># python setup.py install</span></pre></div></div>

<p><strong>Step 4.</strong> make a copy of default configuration file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /usr/share/denyhosts/</span>
<span style="color: #666666; font-style: italic;"># cp denyhosts.cfg-dist denyhosts.cfg</span></pre></div></div>

<p><strong>Step 5.</strong> Edit the configuration file to suit your needs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi denyhosts.cfg</span></pre></div></div>

<p><strong>Step 6.</strong> You can run DenyHosts by cron or as Daemon. preferred way is to run it as daemon. To run it as daemon, make a copy of its default daemon script</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cp daemon-control-dist daemon-control</span></pre></div></div>

<p><strong>Step 7.</strong> Set proper permissions for daemon script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># chown root daemon-control</span>
<span style="color: #666666; font-style: italic;"># chmod 700 daemon-control</span></pre></div></div>

<p><strong>Step 8.</strong> Start it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ./daemon-control start</span></pre></div></div>

<p><strong>Step 9.</strong> Make it run on startup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /etc/init.d</span>
<span style="color: #666666; font-style: italic;"># ln -s /usr/share/denyhosts/daemon-control denyhosts</span>
<span style="color: #666666; font-style: italic;"># chkconfig -–add denyhosts</span></pre></div></div>

<p><strong>Step 10.</strong> You can view its log and also view the hosts.deny file to find out how many hosts are denied:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># tail /var/log/denyhosts</span>
<span style="color: #666666; font-style: italic;"># cat /etc/hosts.deny</span></pre></div></div>

<p>One other way to prevent such attacks is to use tcpwrappers and allow services (ssh) from specific IP Addresses only.</p>
<p>More related and helpful articles:<br />
* <a href="http://linuxadminzone.com/5-steps-to-secure-your-linux-server/"> 5 steps to secure your Linux Server </a><br />
* <a href="http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/"> Ensuring secure access to production Linux Servers </a><br />
* <a href="http://linuxadminzone.com/bash-script-to-backup-essential-log-files-of-linux-server/"> Bash script to backup essential log files in Linux </a><br />
* <a href="http://linuxadminzone.com/quickly-change-your-ssh-port-from-default-22-to-something-higher/"> Quickly change your ssh port from defualt 22 to something higher </a><br />
* <a href="http://linuxadminzone.com/ssh-port-forwarding-from-remote-to-local-machine/"> SSH port forwarding from remote to local machine </a><br />
* <a href="http://linuxadminzone.com/save-root-or-user-history-to-check-later/"> Save root or user history to check later </a> </p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/install-and-configure-denyhost/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

