<?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>Marius van Witzenburg &#187; Shell</title>
	<atom:link href="http://mariusvw.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusvw.com</link>
	<description>&#34;Learned my lesson in life, now setting my action to stay in life.&#34;</description>
	<lastBuildDate>Thu, 09 Sep 2010 08:23:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating SFTP-only User Accounts to Kill SSH Access</title>
		<link>http://mariusvw.com/2010/08/26/creating-sftp-only-user-accounts-to-kill-ssh-access/</link>
		<comments>http://mariusvw.com/2010/08/26/creating-sftp-only-user-accounts-to-kill-ssh-access/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 10:29:23 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[Secure]]></category>
		<category><![CDATA[Sftp]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=4984</guid>
		<description><![CDATA[Problem Statement We wanted to create SFTP-only user accounts that cannot SSH into the server to run commands. There is no built-in approach to this problem that we can find so we created a simple shell script to solve it. Here we will discuss how it works. Step 1: Create a shell script to run [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
We wanted to create SFTP-only user accounts that cannot SSH into the server to run commands. There is no built-in approach to this problem that we can find so we created a simple shell script to solve it. Here we will discuss how it works.</p>
<p><strong>Step 1: Create a shell script to run as the user’s shell</strong></p>
<p>Create a shell script called <em>/sbin/sftp-only</em> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$*&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;-c /usr/libexec/sftp-server&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> “Sorry, <span style="color: #c20cb9; font-weight: bold;">ssh</span> access not allowed.”
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>sftp-server</pre></div></div>

<p><strong>Step 2: Edit user accounts to use this shell script as user’s shell</strong></p>
<p>Modify user accounts using <em>usermod</em> to set the shell to <em>/sbin/sftp-only</em> so that when user tries to SSH to the server, the shell script will display the “Sorry, ssh access not allowed.” message. And when the user tries to connect to the server via a SFTP client, the shell script will get executed and it will start the SFTP server for the user.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2010/08/26/creating-sftp-only-user-accounts-to-kill-ssh-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shellproxy, an easy tool to run shell commands from PHP or other languages</title>
		<link>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/</link>
		<comments>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 19:53:02 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Return]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Value]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1302</guid>
		<description><![CDATA[This is a simple script that runs a shell command from PHP with the function system(). It sometimes happens that a command doesn't close the stdin or stdout, resulting the system() function to halt and wait for it to finish... This causes PHP to reach the 30 second time limit and kill the script. This [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple script that runs a shell command from <a href='http://www.php.net' rel='external ' title=''>PHP</a> with the function system().<br />
It sometimes happens that a command doesn't close the stdin or stdout, resulting the system() function to halt and wait for it to finish...<br />
This causes <a href='http://www.php.net' rel='external ' title=''>PHP</a> to reach the 30 second time limit and kill the script.</p>
<p>This script runs it in the background and you could make your commands send their output to a log file and still having full control.</p>
<p>Read the code below how to use it.</p>
<p>You can compile it by placing the code into 'shellproxy.c' and then compile it with the following command:</p>
<p><code>gcc -o shellproxy shellproxy.c</code></p>
<p>I hope this is something useful for you as it was for me.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio .h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib .h&gt;</span>
<span style="color: #339933;">#include &lt;string .h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> command<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> t<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Shell Proxy<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;By Marius van Witzenburg &lt;http ://mariusvw.com&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;You will mostly use this program from PHP or any other<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;webscripting language to background run programs<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;- CLI:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;shellproxy <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;cmd&gt; &lt;arg&gt;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;shellproxy <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;cmd&gt; &lt;arg&gt; &gt; redirect.txt<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;- PHP:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;system('shellproxy <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;cmd&gt; &lt;arg&gt; &amp;<span style="color: #000099; font-weight: bold;">\&quot;</span>');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;system('shellproxy <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;cmd&gt; &lt;arg&gt; &gt; redirect.txt<span style="color: #000099; font-weight: bold;">\&quot;</span>');<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    command<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>t <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> t <span style="color: #339933;">&lt;</span> argc<span style="color: #339933;">;</span> t<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        strcat<span style="color: #009900;">&#40;</span>command<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>t<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        strcat<span style="color: #009900;">&#40;</span>command<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    fclose<span style="color: #009900;">&#40;</span>stdin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fclose<span style="color: #009900;">&#40;</span>stdout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fclose<span style="color: #009900;">&#40;</span>stderr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    system<span style="color: #009900;">&#40;</span>command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It would be nice if you keep my name mentioned into this code if you use it.</p>
<p>Ps. Donations are welcome... <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' title="Shellproxy, an easy tool to run shell commands from PHP or other languages photo" /> </p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtualbox VDI to VMware VMDK with Qemu script</title>
		<link>http://mariusvw.com/2009/10/18/virtualbox-vdi-to-vmware-vmdk-with-qemu-script/</link>
		<comments>http://mariusvw.com/2009/10/18/virtualbox-vdi-to-vmware-vmdk-with-qemu-script/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 19:32:54 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Convert]]></category>
		<category><![CDATA[Donation]]></category>
		<category><![CDATA[Harddisk]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SH]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[VDI]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[Vmdk]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1101</guid>
		<description><![CDATA[This script converts your VDI image to a VMDK image if you installed Virtualbox and Qemu on the default location of your Mac OS X. I placed this script in my home directory as vdi2vmdk.sh but you could place it anywere you want. The code of vdi2vmdk.sh: 1 2 3 4 5 6 7 8 [...]]]></description>
			<content:encoded><![CDATA[<p>This script converts your VDI image to a VMDK image if you installed Virtualbox and Qemu on the default location of your Mac OS X.</p>
<p>I placed this script in my home directory as <em>vdi2vmdk.sh</em> but you could place it anywere you want.</p>
<p>The code of <em>vdi2vmdk.sh</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;VDI 2 Raw...&quot;</span>
<span style="color: #007800;">ri</span>=<span style="color: #ff0000;">&quot;svi2raw.tmp&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ri</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> 
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span> 
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$ri</span>  
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>VirtualBox.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>VBoxManage internalcommands converttoraw <span style="color: #660033;">-format</span> vdi <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ri</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Raw to VMDK...&quot;</span>
<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Q.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>qemu-img convert <span style="color: #660033;">-O</span> vmdk <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ri</span>&quot;</span> <span style="color: #ff0000;">&quot;$2&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ri</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DONE!&quot;</span></pre></td></tr></table></div>

<p>If you have any questions, please ask...</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2009/10/18/virtualbox-vdi-to-vmware-vmdk-with-qemu-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restrict users to SFTP only instead of full SSH access</title>
		<link>http://mariusvw.com/2009/09/27/restrict-users-to-sftp-only-instead-of-full-ssh-access/</link>
		<comments>http://mariusvw.com/2009/09/27/restrict-users-to-sftp-only-instead-of-full-ssh-access/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 09:35:39 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[Account]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sftp]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1027</guid>
		<description><![CDATA[In case you want users to have access to files on your server but you don't want them to be able to execute commands you can limit them to sftp only access. Add a user to your system like you normally do with an password and then run the following command: usermod -s /usr/libexec/sftp-server username [...]]]></description>
			<content:encoded><![CDATA[<p>In case you want users to have access to files on your server but you don't want them to be able to execute commands you can limit them to sftp only access.</p>
<p>Add a user to your system like you normally do with an password and then run the following command:</p>
<pre>
usermod -s /usr/libexec/sftp-server username
</pre>
<p>Then change add the following to /etc/shells to make it a valid shell:</p>
<pre>
echo '/usr/libexec/sftp-server' >> /etc/shells
</pre>
<p>Now this user can only run the sftp server as shell <img src='http://mariusvw.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Restrict users to SFTP only instead of full SSH access photo" /> </p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2009/09/27/restrict-users-to-sftp-only-instead-of-full-ssh-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
