<?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>Mike Gerwitz &#187; bash</title>
	<atom:link href="http://mikegerwitz.com/tags/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikegerwitz.com</link>
	<description>Free Software Hacker</description>
	<lastBuildDate>Wed, 04 Jan 2012 23:15:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SSH public key still prompting for password</title>
		<link>http://mikegerwitz.com/2010/11/02/ssh-public-key-still-prompting-for-password/</link>
		<comments>http://mikegerwitz.com/2010/11/02/ssh-public-key-still-prompting-for-password/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 21:57:42 +0000</pubDate>
		<dc:creator>Mike Gerwitz</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://mikegerwitz.com/?p=401</guid>
		<description><![CDATA[This was one of those problems that irritated me considerably, since the solution was the last thing that I tried. The issue was that, I noticed, my private key for one of my users on one of my boxes was no longer being accepted. It was still prompting for the password. I tried regenerating the [...]]]></description>
			<content:encoded><![CDATA[<p>This was one of those problems that irritated me considerably, since the solution was the last thing that I tried. The issue was that, I noticed, my private key for one of my users on one of my boxes was no longer being accepted. It was still prompting for the password. I tried regenerating the key, clearing out <tt>~/.ssh/authorized_keys</tt>, reconfiguring ssh, reinstalling <acronym title="Secure Shell">SSH</acronym>&#8230;of course, the logical thing to do would have been to check the logs. But for whatever reason, I saved that for last.</p>
<p>When attempting to log into the server, I was prompted for a password as if the server did not have my public key. It certainly did. Checking <tt>/var/log/auth.log</tt>, I noticed this:</p>
<blockquote><p>
# /var/log/auth.log<br />
Nov  2 17:47:37 hostname sshd[2053]: Authentication refused: bad ownership or modes for directory /home/myuser
</p></blockquote>
<p>Somehow (likely due to user error), the permissions for <tt>/home/myuser</tt> was set to <tt>0777</tt>!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p401code4'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4014"><td class="code" id="p401code4"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lah</span> <span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> myuser
drwxrwxrwx <span style="color: #000000;">119</span> myuser myuser 8.0K <span style="color: #000000;">2010</span>-<span style="color: #000000;">11</span>-02 <span style="color: #000000;">17</span>:<span style="color: #000000;">45</span> myuser</pre></td></tr></table></div>

<p>The solution was to restore the directory permissions to what they should be &#8211; r/w access for the owner only.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p401code5'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4015"><td class="code" id="p401code5"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> 0755 ~myuser
$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lah</span> <span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> myuser
drwxr-xr-x <span style="color: #000000;">119</span> myuser myuser 8.0K <span style="color: #000000;">2010</span>-<span style="color: #000000;">11</span>-02 <span style="color: #000000;">17</span>:<span style="color: #000000;">45</span> myuser</pre></td></tr></table></div>

<p>Hopefully now you&#8217;ll be able to log in with your private key.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p401code6'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4016"><td class="code" id="p401code6"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> myhost
$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>auth.log
Nov  2 17:50:36 <span style="color: #c20cb9; font-weight: bold;">hostname</span> sshd<span style="color: #7a0874; font-weight: bold;">&#91;</span>2212<span style="color: #7a0874; font-weight: bold;">&#93;</span>: Accepted publickey <span style="color: #000000; font-weight: bold;">for</span> myuser from 192.168.1.XXX port XXXXX ssh2</pre></td></tr></table></div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fmikegerwitz.com%2F2010%2F11%2F02%2Fssh-public-key-still-prompting-for-password%2F&amp;linkname=SSH%20public%20key%20still%20prompting%20for%20password">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://mikegerwitz.com/2010/11/02/ssh-public-key-still-prompting-for-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ssh-copy-id and sshd port</title>
		<link>http://mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/</link>
		<comments>http://mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 03:21:57 +0000</pubDate>
		<dc:creator>Mike Gerwitz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/</guid>
		<description><![CDATA[For security purposes, I don&#8217;t run sshd on the default port (22). This gave me some problems when attempting to use the command ssh-copy-id. Ideally, you&#8217;d expect the following to work:

?View Code BASH1
ssh-copy-id -p XXXX -i '~/.ssh/id_rsa.pub' username@host

However, that didn&#8217;t do anything but output an error:
Bad port 'umask 077; test -d .ssh &#124;&#124; mkdir .ssh [...]]]></description>
			<content:encoded><![CDATA[<p>For security purposes, I don&#8217;t run sshd on the default port (22). This gave me some problems when attempting to use the command <tt>ssh-copy-id</tt>. Ideally, you&#8217;d expect the following to work:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p120code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1208"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p120code8"><pre class="bash" style="font-family:monospace;">ssh-copy-id <span style="color: #660033;">-p</span> XXXX <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'~/.ssh/id_rsa.pub'</span> username<span style="color: #000000; font-weight: bold;">@</span>host</pre></td></tr></table></div>

<p>However, that didn&#8217;t do anything but output an error:</p>
<p><tt>Bad port 'umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys'</tt></p>
<p>The solution was to enclose it in quotes as follows:</p>
<p>ssh-copy-id &#8216;-p XXXX -i ~/.ssh/id_rsa.pub username@host&#8217;</p>
<p>Hope that helps.</p>
<p>(The above error probably doesn&#8217;t make any sense. <tt>ssh-copy-id</tt> is a shell script. The command that appears in the error message is a command sent to the server via <acronym title="Secure Shell">SSH</acronym>. Feel free to take a look at the file: <tt>cat `locate ssh-copy-id | head -n1`</tt>)</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fmikegerwitz.com%2F2009%2F10%2F07%2Fssh-copy-id-and-sshd-port%2F&amp;linkname=ssh-copy-id%20and%20sshd%20port">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>compgen -d: No such file or directory</title>
		<link>http://mikegerwitz.com/2009/08/25/compgen-d-no-such-file-or-directory/</link>
		<comments>http://mikegerwitz.com/2009/08/25/compgen-d-no-such-file-or-directory/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 03:47:52 +0000</pubDate>
		<dc:creator>Mike Gerwitz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[GNU/Linux]]></category>

		<guid isPermaLink="false">http://www.mikegerwitz.com/2009/08/25/compgen-d-no-such-file-or-directory/</guid>
		<description><![CDATA[For a while, I was having a problem on my Ubuntu server. After creating a user, I noticed that tab completion didn&#8217;t work properly. In fact, it went so far as to output an error:

]]></description>
			<content:encoded><![CDATA[<p>For a while, I was having a problem on my Ubuntu server. After creating a user, I noticed that tab completion didn&#8217;t work properly. In fact, it went so far as to output an error:<br />
<code><br />
<( compgen -d -- '/my/dir' ): No such file or directory</code></p>
<p>Where "/my/dir" would vary depending on what you're tab-completing. I suspected the problem might be with permissions, but that came up short.</p>
<p>I finally came across the solution here:</p>
<p><a href="http://serverfault.com/questions/47554/ubuntu-tab-completon-and-mc-problems">http://serverfault.com/questions/47554/ubuntu-tab-completon-and-mc-problems</a></p>
<p>Since I had trouble finding much information on Google, hopefully this post will help. It turned out to be a shell issue. When I created the user, I never specified the default shell to use (<acronym title="Bourne Again Shell">BASH</acronym>), and I apparently never went back and changed it. Which explains why it worked on some of my users' accounts but not others.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fmikegerwitz.com%2F2009%2F08%2F25%2Fcompgen-d-no-such-file-or-directory%2F&amp;linkname=compgen%20-d%3A%20No%20such%20file%20or%20directory">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://mikegerwitz.com/2009/08/25/compgen-d-no-such-file-or-directory/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Clearing BASH Command History</title>
		<link>http://mikegerwitz.com/2008/09/07/clearing-bash-command-history/</link>
		<comments>http://mikegerwitz.com/2008/09/07/clearing-bash-command-history/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 07:48:35 +0000</pubDate>
		<dc:creator>Mike Gerwitz</dc:creator>
				<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Guides]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://www.mikegerwitz.com/2008/09/07/clearing-bash-command-history/</guid>
		<description><![CDATA[BASH (bourne again shell), the default shell used on many GNU/Linux distributions, keeps a history of all commands entered. This can be a great convenience. However, scrolling back, I saw a number of commands I would prefer gone in case somebody decided to snoop around my system. Especially the commands where I accidently entered the [...]]]></description>
			<content:encoded><![CDATA[<p><acronym title="Bourne Again Shell">BASH</acronym> (bourne again shell), the default shell used on many <acronym title="GNU's Not Unix!">GNU</acronym>/Linux distributions, keeps a history of all commands entered. This can be a great convenience. However, scrolling back, I saw a number of commands I would prefer gone in case somebody decided to snoop around my system. Especially the commands where I accidently entered the root password in the shell. I&#8217;m sure it&#8217;s happened to many of you before too &#8211; you think you type &#8220;su&#8221;, but something happens and it doesn&#8217;t enter. So then you type your password, not noticing (in my case, I may be reading a chat or article while I&#8217;m typing it in), and then BAM &#8211; it&#8217;s entered in the <acronym title="Bourne Again Shell">BASH</acronym> command history.</p>
<p>So, when going through my home folder one day, I came across a hidden file called <tt>.bash_history</tt>. Hmm, I wondered. Could this solve my problem? Yes! It can!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p38code12'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3812"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p38code12"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">rm</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_history
<span style="color: #666666; font-style: italic;"># You can also clear your history with the following command:</span>
$ <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #660033;">-c</span></pre></td></tr></table></div>

<p>After deleting the file, open <acronym title="Bourne Again Shell">BASH</acronym> and hit the up key &#8211; you should get nothing but a pleasant beep. A wonderful representation of security. Of course, it&#8217;d be best to shred the file using a utility such as, well, <tt>shred</tt>, so that nobody can retrieve the deleted contents. Note that you can only use the below command to shred the file if you haven&#8217;t already deleted it.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p38code13'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3813"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p38code13"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">shred</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_history</pre></td></tr></table></div>

<p>And all should be well. But, what if you don&#8217;t want it to keep a track of your history? Well, there&#8217;s a couple ways to do so. I pulled the examples from the following link:</p>
<p><a href="http://gentoo-wiki.com/SECURITY_Bash_History_Functions">http://gentoo-wiki.com/SECURITY_Bash_History_Functions</a></p>
<p>The easiest one, which I did (I don&#8217;t feel like wasting any more time on this), was the following command:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p38code14'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3814"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p38code14"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null ~<span style="color: #000000; font-weight: bold;">/</span>.bash_history</pre></td></tr></table></div>

<p>This creates a link so that <tt>.bash_history</tt> points to <tt>/dev/null</tt>. Anything sent to <tt>/dev/null</tt> never returns &#8211; thus the name. It is simply discarded.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fmikegerwitz.com%2F2008%2F09%2F07%2Fclearing-bash-command-history%2F&amp;linkname=Clearing%20BASH%20Command%20History">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://mikegerwitz.com/2008/09/07/clearing-bash-command-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
