<?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>unixwiz &#187; readonly shell</title>
	<atom:link href="http://blogs.sungeek.net/unixwiz/tag/readonly-shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.sungeek.net/unixwiz</link>
	<description>anything dealing with *NIX or what ever I want to write about</description>
	<lastBuildDate>Wed, 04 Aug 2010 03:04:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ultra Restricted Shell in Solaris</title>
		<link>http://blogs.sungeek.net/unixwiz/2009/02/19/ultra-restricted-shell-in-solaris/</link>
		<comments>http://blogs.sungeek.net/unixwiz/2009/02/19/ultra-restricted-shell-in-solaris/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 03:18:06 +0000</pubDate>
		<dc:creator>unixwiz</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[rbash]]></category>
		<category><![CDATA[readonly shell]]></category>

		<guid isPermaLink="false">http://blogs.sungeek.net/unixwiz/?p=1068</guid>
		<description><![CDATA[How to setup a readonly environment on Solaris: If you want to give a specific user readonly access to your solaris machine via ssh, and want to log everything they do, it is sort of easy to setup. Here is a quick step-by-step guide to setting it up. 1. First you will need to chose [...]]]></description>
			<content:encoded><![CDATA[<p>How to setup a readonly environment on Solaris:</p>
<p>If you want to give a specific user readonly access to your solaris machine via ssh, and want to log everything they do, it is sort of easy to setup. Here is a quick step-by-step guide to setting it up.</p>
<p>1. First you will need to chose what restricted shell you want to use. In this case I used bash as I wanted the .bash_history file to contain the exact time every command was run on the system. Since Solaris does not come with the rbash command, the only thing you need to do is make a copy of /usr/bin/bash to /usr/bin/rbash. </p>
<p>2. Make the user&#8217;s shell be /usr/bin/rbash, this will make them use the restricted bash shell. </p>
<p>3. Make their home directory owned by root. </p>
<p>4. Make their .profile owned by root</p>
<p>5. Create a .bash_history file and make it owned by that user. This should be the only file in their directory that is owned by the user. </p>
<p>6. Pick a location for your &#8220;restricted&#8221; binaries to reside. If this user will be logging in to multiple machines and you have a shared file system (say /home) I would suggest making the directory in /home; say /home/rbin.. This way you only have to put /home/rbin in their PATH.</p>
<p>7. Make symbolic links in your restricted binary directory to the binaries you want to run. I.e. ls, ps, more, prstat,passwd and hostname :</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">17</span> Feb <span class="nu0">19</span> <span class="nu0">20</span>:<span class="nu0">47</span> <span class="kw2">hostname</span> -&gt; /usr/bin/<span class="kw2">hostname</span>*<br />
lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">11</span> Feb <span class="nu0">19</span> <span class="nu0">19</span>:<span class="nu0">56</span> <span class="kw2">ls</span> -&gt; /usr/bin/<span class="kw2">ls</span>*<br />
lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">13</span> Feb <span class="nu0">19</span> <span class="nu0">19</span>:<span class="nu0">57</span> <span class="kw2">more</span> -&gt; /usr/bin/<span class="kw2">more</span>*<br />
lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">15</span> Feb <span class="nu0">19</span> <span class="nu0">19</span>:<span class="nu0">56</span> prstat -&gt; /usr/bin/prstat*<br />
lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">11</span> Feb <span class="nu0">19</span> <span class="nu0">19</span>:<span class="nu0">56</span> <span class="kw2">ps</span> -&gt; /usr/bin/<span class="kw2">ps</span>*<br />
lrwxrwxrwx &nbsp; <span class="nu0">1</span> root &nbsp; &nbsp; root &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">11</span> Feb <span class="nu0">19</span> <span class="nu0">19</span>:<span class="nu0">56</span> <span class="kw2">passwd</span> -&gt; /usr/bin/<span class="kw2">passwd</span>*</div>
</div>
<p>By making these sym links instead of the actual binaries, you do not have to worry if you have multiple platforms that you are going between (i.e. Sparc, x86) and doing custom logic to use the right binary.</p>
<p>8. Create the users .profile with the following in it:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw3">readonly</span> <span class="re2">PATH=</span>/home/rbin<br />
<span class="kw3">readonly</span> <span class="re2">TMOUT=</span><span class="nu0">900</span><br />
<span class="kw3">readonly</span> <span class="re2">EXTENDED_HISTORY=</span>ON<br />
<span class="kw3">readonly</span> <span class="re2">HOSTNAME=</span><span class="st0">&quot;`hostname`&quot;</span><br />
<span class="kw3">readonly</span> <span class="kw3">export</span> <span class="re2">HISTTIMEFORMAT=</span><span class="st0">&quot;%F %T &quot;</span><br />
<span class="kw3">readonly</span> <span class="kw3">export</span> <span class="re2">PS1=</span><span class="st0">&#8216;${HOSTNAME}:${PWD}&gt; &#8216;</span></div>
</div>
<p>This will make it so they can not change any of the Environment variables. It sets their path to /home/rbin. Sets a inactivity time out to be 15 minutes. Sets the extended history to be on (this logs the time each command was executed in their .bash_history file). And finally sets their prompt and makes it readonly as well.</p>
<p>9. The last thing you need to do is change the permissions on the scp and sftp-server binaries so that the user can not execute them. Otherwise, they would be able to download files and go any where on the server they want. (Restricted shell will prevent them from cd&#8217;ing out of their home directory) To do this, I created a group and put my user in it as their primary group. Say the group was called rdonly. Now I do the following:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">setfacl -m group:rdonly:&#8212; /usr/lib/<span class="kw2">ssh</span>/sftp-server<br />
setfacl -m group:rdonly:&#8212; /usr/bin/<span class="kw2">scp</span></div>
</div>
<p>So the files should show up like this now:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">bash<span class="nu0">-3.00</span><span class="re3"># <span class="kw2">ls</span> -la /usr/lib/<span class="kw2">ssh</span>/sftp-server /usr/bin/scp</span><br />
-r-xr-xr-x+ &nbsp;<span class="nu0">1</span> root &nbsp; &nbsp; bin &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">40484</span> Jan <span class="nu0">22</span> &nbsp;<span class="nu0">2005</span> /usr/bin/<span class="kw2">scp</span><br />
-r-xr-xr-x+ &nbsp;<span class="nu0">1</span> root &nbsp; &nbsp; bin &nbsp; &nbsp; &nbsp; &nbsp;<span class="nu0">35376</span> Jan <span class="nu0">22</span> &nbsp;<span class="nu0">2005</span> /usr/lib/<span class="kw2">ssh</span>/sftp-server</div>
</div>
<p>And the getfacl will look like this:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">bash<span class="nu0">-3.00</span><span class="re3"># getfacl /usr/bin/scp</span></p>
<p><span class="re3"># <span class="kw2">file</span>: /usr/bin/scp</span><br />
<span class="re3"># owner: root</span><br />
<span class="re3"># group: bin</span><br />
user::r-x<br />
group::r-x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re3">#effective:r-x</span><br />
group:rdonly:&#8212; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re3">#effective:&#8212;</span><br />
mask:r-x<br />
other:r-x</div>
</div>
<p>This makes it so when the user tries to sftp or scp in to the machine, it will immediately disconnect them as they don&#8217;t have permissions to run those 2 executables.</p>
<p>That is about it. Don&#8217;t forget to set their password, make sure it has a policy set on it to be changed often and require a combination of letters, numbers and special characters and that it is at least 8 characters in length.</p>
<p>So now when the user logs in they will see something similar to this:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="br0">&#91;</span>laptop:~<span class="br0">&#93;</span> unixwiz% <span class="kw2">ssh</span> unixwiz@fozzy<br />
Password: <br />
Last <span class="kw2">login</span>: Thu Feb <span class="nu0">19</span> <span class="nu0">22</span>:<span class="nu0">10</span>:<span class="nu0">15</span> <span class="nu0">2009</span> from laptop<br />
fozzy:/home/unixwiz&gt; <span class="kw3">cd</span> /<br />
-<span class="kw2">rbash</span>: <span class="kw3">cd</span>: restricted<br />
fozzy:/home/unixwiz&gt; vi /tmp/<span class="kw3">test</span><br />
-<span class="kw2">rbash</span>: vi: <span class="kw3">command</span> not found<br />
fozzy:/home/unixwiz&gt; <span class="re2">PATH=</span><span class="re1">$PATH</span>:/usr/bin<br />
-<span class="kw2">rbash</span>: PATH: <span class="kw3">readonly</span> variable<br />
fozzy:/home/unixwiz&gt; timed out waiting <span class="kw1">for</span> input: auto-<span class="kw3">logout</span></div>
</div>
<p>As you can see, it will give you errors if you try to do something that you are not allowed to do. The last line shows the time out message where it closes the connection due to inactivity.</p>
<p>Now if the administrator goes and looks at the users .bash_history file they would see this:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="re3">#<span class="nu0">1235099570</span></span><br />
<span class="kw3">cd</span> /<br />
<span class="re3">#<span class="nu0">1235099577</span></span><br />
vi /tmp/<span class="kw3">test</span><br />
<span class="re3">#<span class="nu0">1235099587</span></span><br />
<span class="re2">PATH=</span><span class="re1">$PATH</span>:/usr/bin</div>
</div>
<p>The #number is the exact time that the user ran the command below it. The item is the seconds since the epoch&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.sungeek.net/unixwiz/2009/02/19/ultra-restricted-shell-in-solaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
