<?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; ssh</title>
	<atom:link href="http://linuxadminzone.com/tag/ssh/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>SSH Port forwarding from remote to local machine</title>
		<link>http://linuxadminzone.com/ssh-port-forwarding-from-remote-to-local-machine/</link>
		<comments>http://linuxadminzone.com/ssh-port-forwarding-from-remote-to-local-machine/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 07:32:44 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[port forwarding]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=19</guid>
		<description><![CDATA[SSH has a wonderful feature called SSH Port Forwarding, also known as SSH Tunneling, which allows you to establish a secure SSH session and then tunnel arbitrary TCP connections through it. Tunnels can be created at any time, with almost no effort and no programming, which makes them very appealing. Here I&#8217;ll illustrate it using [...]]]></description>
			<content:encoded><![CDATA[<p>SSH has a wonderful feature called SSH Port Forwarding, also known as SSH Tunneling, which allows you to establish a secure SSH session and then tunnel arbitrary TCP connections through it. Tunnels can be created at any time, with almost no effort and no programming, which makes them very appealing.</p>
<p>Here I&#8217;ll illustrate it using an example. Suppose you have installed and configured Jabber Instant Messaging Server (check out to do that on this site <a href="http://linuxadminzone.com/install-and-configure-ejabberd-jabber-im-server/">here</a>). You found later that in the Server machine, there&#8217;s no GUI available and you need to access its graphical web admin interface. In this case, you can easily forward port from Server machine to your own PC to access the admin interface. You might know that ejabberd (Jabber Server) web admin interface is available on port 5280. </p>
<p>Just for checking, try once to telnet to port 5280 on locahost:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>Desktop<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># telnet localhost 5280</span>
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host: Connection refused</pre></div></div>

<p>The connection was refused as there&#8217;s no service to entertain the request on specified port. </p>
<p>Let&#8217;s do the forwarding now. The syntax is: ssh -L <em>localport:remotehost:remoteport remotehostip</em></p>
<p>Here is the example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>Desktop<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ssh -L 5280:localhost:5280 192.168.0.38</span>
Password: <span style="color: #000000; font-weight: bold;">******</span></pre></div></div>

<p>It should come to remote server shell, leave it as is. </p>
<p>You will be logged in Server and the specified port will be forwarded to your host. Sometimes, its uncomfortable to login in the Server while we just need to do only port forwarding, you can avoid logging in Server by using -N option with ssh command.</p>
<p>Just jump to another another shell and try to telnet localhost now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>Desktop<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># telnet localhost 5280</span>
Trying 127.0.0.1...
Connected to localhost.localdomain <span style="color: #7a0874; font-weight: bold;">&#40;</span>127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Escape character is <span style="color: #ff0000;">'^]'</span>.</pre></div></div>

<p>Cool. you are able to connect. Open your browser and type: http://localhost:5280/admin/ to open the web admin interface of ejabberd IM Server.</p>
<p>You may also like to read:<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><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/ssh-port-forwarding-from-remote-to-local-machine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

