<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>Fabian Moser &#187; SSH</title>
	<atom:link href="http://fabianmoser.at/schlagwort/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://fabianmoser.at</link>
	<description>&#34;as simple as possible, but not simpler&#34;</description>
	<lastBuildDate>Thu, 26 Jan 2012 13:19:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/at/</creativeCommons:license>		<item>
		<title>Fedora 14 and SSH port forwarding</title>
		<link>http://fabianmoser.at/blog/2010/11/11/fedora-14-and-ssh-port-forwarding/</link>
		<comments>http://fabianmoser.at/blog/2010/11/11/fedora-14-and-ssh-port-forwarding/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 08:30:26 +0000</pubDate>
		<dc:creator>Fabian Moser</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.fabianmoser.at/?p=848</guid>
		<description><![CDATA[Yesterday I upgraded also my workstation to Fedora 14 and soon ran into a rather unexpected problem that I couldn&#8217;t resolve due to an overwhelming amount of misleading reports and discussions on the web a.k.a. &#8220;noise&#8221;. The use-case was, that &#8230; <a href="http://fabianmoser.at/blog/2010/11/11/fedora-14-and-ssh-port-forwarding/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I upgraded also my workstation to Fedora 14 and soon ran into a rather unexpected problem that I couldn&#8217;t resolve due to an overwhelming amount of misleading reports and discussions on the web a.k.a. &#8220;noise&#8221;. The use-case was, that I tunnel from home to my workstation via SSH on a regular basis and for different purposes. After yesterdays upgrade I double-checked that all firewall settings are OK to permit the connection before I went home. Initialising the tunnel later that evening went without a problem, but using it issued a weird error:</p>

<div class="wp_syntax"><div class="code"><pre class="email" style="font-family:monospace;">channel 2: open failed: administratively prohibited: open failed</pre></div></div>

<p>A search on the web yielded all kinds of results, mostly referring to settings in the SSH daemon. All solutions either mentioned <code>AllowTcpForwarding</code>, which is anyway <code>yes</code> by default, or <code>PermitTunnel</code>, which has nothing to do with port forwarding. As was to be expected, these hints didn&#8217;t help in my case.</p>
<p>Desperate to find more useful keyword for a search, I ran <code>ssh</code> in verbose mode (with <code>-vvv</code>), which gave (global IP addresses are replaced by <code>X.X.X.X</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="email" style="font-family:monospace;">debug1: Connection to port 11080 forwarding to socks port 0 requested.
debug2: fd 8 setting TCP_NODELAY
debug2: fd 8 setting O_NONBLOCK
debug3: fd 8 is O_NONBLOCK
debug1: channel 2: new [dynamic-tcpip]
debug2: channel 2: pre_dynamic: have 0
debug2: channel 2: pre_dynamic: have 3
debug2: channel 2: decode socks5
debug2: channel 2: socks5 auth done
debug2: channel 2: pre_dynamic: need more
debug2: channel 2: pre_dynamic: have 0
debug2: channel 2: pre_dynamic: have 10
debug2: channel 2: decode socks5
debug2: channel 2: socks5 post auth
debug2: channel 2: dynamic request: socks5 host X.X.X.X port 80 command 1
channel 2: open failed: administratively prohibited: open failed
debug2: channel 2: zombie
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 11080 for X.X.X.X port 80, connect from 127.0.0.1 port 59418, nchannels 3
debug3: channel 2: status: The following connections are open:
  #1 client-session (t4 r0 i0/0 o0/0 fd 5/6 cc -1)
&nbsp;
debug3: channel 2: close_fds r 8 w 8 e -1</pre></div></div>

<p>No luck either.</p>
<p>Finally, I had the idea that SELinux could interfere here without giving the SSH daemon the possibility of a helpful error message. When I logged into my workstation this morning, the SELinux warning gave the appropriate solution in the form of a command (to be issued by <code>root</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ setsebool <span style="color: #660033;">-P</span> sshd_forward_ports <span style="color: #000000;">1</span></pre></div></div>

<p>This fixed the problem and everything now works as before. \me = happy.</p>
]]></content:encoded>
			<wfw:commentRss>http://fabianmoser.at/blog/2010/11/11/fedora-14-and-ssh-port-forwarding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Einrichtung eines sicheren Fileservers</title>
		<link>http://fabianmoser.at/blog/2010/02/28/einrichtung-eines-sicheren-fileservers/</link>
		<comments>http://fabianmoser.at/blog/2010/02/28/einrichtung-eines-sicheren-fileservers/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 11:15:13 +0000</pubDate>
		<dc:creator>Fabian Moser</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sicherheit]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://fabianmoser.at/?p=584</guid>
		<description><![CDATA[Theorie Bei diesem Titel versteht es sich vielleicht von selbst, dass FTP hier kein Thema ist. Es ist vermutlich zu einem nicht unwesentlichen Teil persönliche Präferenz, aber wenn ich das Wort sicher im Zusammenhang mit Servern verwende, verlasse ich mich &#8230; <a href="http://fabianmoser.at/blog/2010/02/28/einrichtung-eines-sicheren-fileservers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Theorie</h2>
<p>Bei diesem Titel versteht es sich vielleicht von selbst, dass FTP hier kein Thema ist. Es ist vermutlich zu einem nicht unwesentlichen Teil persönliche Präferenz, aber wenn ich das Wort sicher im Zusammenhang mit Servern verwende, verlasse ich mich immer gern auf SSH. Im Fall eines Fileservers bietet sich also das <a href="http://de.wikipedia.org/wiki/SSH_File_Transfer_Protocol">SFTP Protokoll</a> an. Generell wirft die Verwendung von SSH und, im Speziellen, die Weitergabe von Zugangsdaten für einen SSH Server (zumindest) zwei brennende Fragen auf.</p>
<p>Zum einen muss verhindert werden, dass der eingeloggte Benutzer beliebigen Code ausführen kann. Da er zumindest für das Upload Verzeichnis Schreibrechte hat, kann ein eventueller Upload von Exploits nicht prinzipiell verhindert werden, aber wenn man dem Benutzer erst gar keine Shell gibt, kann er die Ausführung des Schadcodes nicht veranlassen. Diese Strategie verfolgt die <a href="http://www.sublimation.org/scponly/wiki/index.php/Main_Page">scponly</a> Software.</p>
<p>Zum anderen ist man als Administator auch interessiert, dem eingeloggten Benutzer möglichst wenig Information über das System preiszugeben. Das erreicht man mit einer <code>chroot</code> Umgebung. Nun wird sogar von scponly ein Skript angeboten, um eine solche Umgebung zu erstellen. Dessen Verwendung wird auf der <a href="http://wiki.ubuntuusers.de/scponly">ubuntuusers Wiki</a> beschrieben. Leider ist dafür das Setzen des SUID Bits notwendig, was meiner Meinung nach keine saubere Lösung ist. Daher werde ich hier beschreiben, wie man eine äquivalente Umgebung mit dem <a href="http://www.floc.net/makejail/"><code>makejail</code></a> Skript erstellt. Diese Vorgehensweise orientiert sich stark an der <a href="http://www.debian.org/doc/manuals/securing-debian-howto/ap-chroot-ssh-env.de.html">Anleitung zum Absichern von Debian</a>, welche in ihrer Gesamtheit auf jeden Fall eine Lektüre wert ist, wenn man einen Debian Server administrieren muss.</p>
<h2>Praxis</h2>
<p>Diese Anleitung bezieht sich auf Debian Lenny. Zuerst werden die erforderlichen Pakete installiert:</p>
<pre># aptitude install libpam-chroot makejail scponly</pre>
<p>Nun wird das eben installierte PAM Modul <code>libpam-chroot</code> für SSH Logins aktiviert. Dazu werden die folgenden Zeilen zu der Datei <code>/etc/pam.d/sshd</code> hinzugefügt:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">session    required     pam_chroot.so</pre></div></div>

<p>Zunächst muss der entsprechende Benutzer erstellt werden, mit dem man sich später am Server anmelden kann.</p>
<pre># adduser --home /home/sftp --shell /usr/bin/scponly --no-create-home sftp</pre>
<p>Damit das PAM Modul auch wirklich greift, muss es für den neuen Benutzer aktiviert werden. Das geschieht durch folgende Zeile in der Datei <code>/etc/security/chroot.conf</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sftp	/var/chroot/users/sftp</pre></div></div>

<p>Als nächstes wird das Verzeichnis für die <code>chroot</code> Umgebung erstellt und der neue Benutzer erhält Schreibrechte für sein Heimatverzeichnis.</p>
<pre># mkdir -p /var/chroot/users/sftp/home/sftp
# chown sftp:sftp /var/chroot/users/sftp/home/sftp</pre>
<p>Für die Verwendung des <code>makejail</code> Skripts wird eine Konfigurationsdatei mit folgendem Inhalt erstellt und als <code>sftp-jail.py</code> gespeichert.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">chroot=<span style="color: #483d8b;">&quot;/var/chroot/users/sftp&quot;</span>
users=<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;sftp&quot;</span><span style="color: black;">&#93;</span>
testCommandsInsideJail=<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;scponly&quot;</span>, <span style="color: #483d8b;">&quot;ls&quot;</span>, <span style="color: #483d8b;">&quot;scp&quot;</span>, <span style="color: #483d8b;">&quot;rm&quot;</span>, <span style="color: #483d8b;">&quot;ln&quot;</span>, <span style="color: #483d8b;">&quot;mv&quot;</span>, <span style="color: #483d8b;">&quot;chmod&quot;</span>, <span style="color: #483d8b;">&quot;chown&quot;</span>, <span style="color: #483d8b;">&quot;chgrp&quot;</span>, <span style="color: #483d8b;">&quot;mkdir&quot;</span>, <span style="color: #483d8b;">&quot;rmdir&quot;</span>, <span style="color: #483d8b;">&quot;pwd&quot;</span>, <span style="color: #483d8b;">&quot;groups&quot;</span>, <span style="color: #483d8b;">&quot;id&quot;</span>, <span style="color: #483d8b;">&quot;echo&quot;</span>, <span style="color: #483d8b;">&quot;passwd&quot;</span><span style="color: black;">&#93;</span>
forceCopy=<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;/usr/lib/sftp-server&quot;</span><span style="color: black;">&#93;</span>
cleanJailFirst=<span style="color: #ff4500;">1</span>
preserve=<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;/home/sftp&quot;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Es folgt der Aufruf des Skripts.</p>
<pre># makejail sftp-jail.py</pre>
<p>Die am Ende ausgegebenen Warnungen können getrost ignoriert werden. Wenn man so vorsichtig ist wie ich, muss man noch dafür sorgen, dass der SSH Login für den neuen Benutzer freigegeben wird. Dazu fügt man den neuen Benutzernamen dem <code>AllowUsers</code> Parameter in der Datei <code>/etc/ssh/sshd_config</code> hinzu und startet das SSH Service neu.</p>
<pre># /etc/init.d/ssh restart</pre>
]]></content:encoded>
			<wfw:commentRss>http://fabianmoser.at/blog/2010/02/28/einrichtung-eines-sicheren-fileservers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

