<?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>The Admin&#039;s Archive &#187; Linux &amp; Unix</title>
	<atom:link href="http://www.on-tap.org/category/unix-linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.on-tap.org</link>
	<description></description>
	<lastBuildDate>Mon, 16 Nov 2009 18:43:03 +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>Creating a Custom Dynamic Pre-login MOTD</title>
		<link>http://www.on-tap.org/2009/10/16/create-a-custom-dynamic-motd/</link>
		<comments>http://www.on-tap.org/2009/10/16/create-a-custom-dynamic-motd/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 01:57:08 +0000</pubDate>
		<dc:creator>Devin</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux & Unix]]></category>

		<guid isPermaLink="false">http://tech.on-tap.org/?p=126</guid>
		<description><![CDATA[Have you ever wanted to create a custom message to be displayed on the Linux pre-login console, which is dynamically updating?
Well, this tutorial will help you do it. I&#8217;ve only tested this on Ubuntu 8.04, so please let me know if it works for other distributions. Thanks!
First, create a shell script to re-generate the /etc/issue [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to create a custom message to be displayed on the Linux pre-login console, which is dynamically updating?</p>
<p>Well, this tutorial will help you do it. I&#8217;ve only tested this on Ubuntu 8.04, so please let me know if it works for other distributions. Thanks!</p>
<p>First, create a shell script to re-generate the /etc/issue file. For this example, I&#8217;ll create a message that shows how to access the webmin interface. <span style="color: #99ccff;">Add this code to a file called /etc/init.d/new_issue.sh:</span><br />
<code><br />
#!/bin/bash<br />
######################################################<br />
# Prints login/port info above console login prompt. #<br />
######################################################<br />
# get configured IP for eth0<br />
IPADDR=$(/sbin/ifconfig eth0 | sed -n 's/.*inet *addr:\([0-9\.]*\).*/\1/p')<br />
# generate new /etc/issue<br />
/bin/echo "Ubuntu 8.04.3 LTS \n \l" &gt; /etc/issue<br />
/bin/echo &gt;&gt; /etc/issue<br />
/bin/echo "************************************************" &gt;&gt; /etc/issue<br />
/bin/echo "Webmin:  https://$IPADDR:12345" &gt;&gt; /etc/issue<br />
/bin/echo "************************************************" &gt;&gt; /etc/issue<br />
/bin/echo &gt;&gt; /etc/issue<br />
exit 0<br />
</code><br />
Once that&#8217;s done, <span style="color: #99ccff;">issue the following commands to make the script executable, and tell Linux to run as one of the last scripts in the default runlevels:</span><br />
<code><br />
[root@linux]$ chmod 755 /etc/init.d/new_issue.sh<br />
[root@linux]$ update-rc.d new_issue.sh defaults 99<br />
</code><br />
This should now replace the default <em>issue</em> message with your custom one. Then reboot, and you should see your new custom message sitting just above your console login!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.on-tap.org/2009/10/16/create-a-custom-dynamic-motd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux &amp; Unix: oft-forgotten commands</title>
		<link>http://www.on-tap.org/2008/11/13/unix-linux-oft-forgotten-commands/</link>
		<comments>http://www.on-tap.org/2008/11/13/unix-linux-oft-forgotten-commands/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 10:33:39 +0000</pubDate>
		<dc:creator>Devin</dc:creator>
				<category><![CDATA[Linux & Unix]]></category>

		<guid isPermaLink="false">http://www.on-tap.org/blog/?p=15</guid>
		<description><![CDATA[Even the most seasoned Unix admin may forget some of the most powerful commands from time to time. I can say there have been several times while administering various flavors of unix and linux that I could have solved a problem with much greater ease had I just remembered that particular god-mode command. These commands [...]]]></description>
			<content:encoded><![CDATA[<p>Even the most seasoned Unix admin may forget some of the most powerful commands from time to time. I can say there have been several times while administering various flavors of unix and linux that I could have solved a problem with much greater ease had I just remembered that particular god-mode command. These commands may vary slightly between distributions, but their function remains the same.</p>
<p>In the interest of preserving god-mode, I hereby present this list of oft-forgotten commands that may help ease a large variety of administrative &amp; troubleshooting tasks. So, without further ado, I present you this:</p>
<h4><strong>10 Commands a&#8217;la god-mode:</strong></h4>
<ul>
<li><span style="text-decoration: underline;"><strong>apropos</strong></span>: This command searches the names &amp; descriptions of man pages for keywords. While it may not be all to <em>oft-forgotten</em>, it is a very useful &amp; important command which I felt was necessary to include.</li>
<li><span style="text-decoration: underline;"><strong>col</strong></span>: Have you ever wanted to save man pages as formatted text files? This command can do it! Try <em>&#8220;man &lt;somebinary&gt; | col -b &gt; somebinary_manpage.txt</em>&#8220;.</li>
<li><strong><span style="text-decoration: underline;">file</span></strong>: So, you found something sitting in some directory, and it has the execute bit set&#8230; Just what is it? Well, <em>&#8220;file&#8221; </em>will tell you!</li>
<li><strong><span style="text-decoration: underline;">fuser</span></strong>: <em>fuser </em>is to PID&#8217;s as <em>lsof </em>is to files. This command does the reverse of <em>lsof</em>, by listing PID&#8217;s for whoever/whatever is using a particular file. Need to kill an entire process group, such as apache and all it&#8217;s spawned threads? try <em>&#8220;fuser -k /var/log/apache2/access.log&#8221;</em>.</li>
<li><strong><span style="text-decoration: underline;">ldd</span></strong>: Displays info about shared libraries. This can come in handy when you have a binary that just doesn&#8217;t function, or doesn&#8217;t function as expected. The solution could be as simple as restoring a particular library file from one of your backups.</li>
<li><span style="text-decoration: underline;"><strong>script</strong></span>: Not everyone in my company is a *nix guru. So, sometimes I have to make a short tutorial for common tasks. That&#8217;s where <em>script </em>comes in! I can just record my terminal session, then print it!</li>
<li><strong><span style="text-decoration: underline;">stat</span></strong>: Need info about a file or directory with a highly customizable format? This is the command for you! Pay close attention to the &#8211;printf option and formats. (notice the similarity to <em>netstat </em>and <em>lstat </em>?)</li>
<li><span style="text-decoration: underline;"><strong>strings</strong></span>: This utility is great for investigating binary files. Ever wonder what programmers put in their programs? This tool can help you find out!</li>
<li><span style="text-decoration: underline;"><strong>time</strong></span>: This command displays the amount of time spent on processing a particular command. This is great for guaging how long a particular operation takes, which can then be used for properly timing automated tasks &amp; such.</li>
<li><strong><span style="text-decoration: underline;">xargs</span></strong>: Again, this isn&#8217;t such an uncommon command. But it&#8217;s very useful and I can&#8217;t help but present it here. Not all commands accept a piped input. This command will let you build a set of arguments for use with other commands.</li>
</ul>
<h4>Putting it all together:</h4>
<p>So, one sunny morning you awake to find your web server is acting a little slower than usual. Since you forgot most of these commands, but still somehow remembered <strong><em>apropos</em></strong>, you are able to figure out the rest, right? Now, suppose you find some strange file in /var/www while poking around. So, you decide to investigate:</p>
<p style="padding-left: 30px;"><span style="color: #008000;"><em>linux:~# apropos &#8220;file type&#8221;<br />
[ (1)                - check file types and compare values<br />
file (1)             - determine file type<br />
test (1)             - check file types and compare values</em></span></p>
<p>Ok, so I'll run<span style="color: #00ffff;"> <em>file /var/www/a.out</em></span></p>
<p style="padding-left: 30px;"><em>l<span style="color: #008000;">inux:~# file /var/www/a.out<br />
/var/www/a.out: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (<strong><span style="text-decoration: underline;">uses shared libs</span></strong>), for GNU/Linux 2.6.0, not stripped</span><br />
</em></p>
<p>Ok, so it's an executable using shared libraries... hmm... so let's run<span style="color: #00ffff;"> <em>ldd /var/www/a.out</em></span> and see what we find...</p>
<p style="padding-left: 30px;"><span style="color: #008000;">linux:~# ldd /var/www/a.out<br />
libc.so.6 =&gt; /lib/libc.so.6 (0x00002ae9c0211000)<br />
/lib64/ld-linux-x86-64.so.2 (0x00002ae9c00f9000)</span></p>
<p>Well, it looks like it was possibly written in the C or C++ programming languages. And it's using just a couple common libraries for those types of programs.</p>
<p>So, what's this file's deal? Let's run <span style="color: #00ffff;"><em>stat /var/www/a.out</em></span></p>
<p style="padding-left: 30px;"><span style="color: #008000;">linux:~# stat /var/www/a.out<br />
File: `/var/www/a.out'<br />
Size: 8597            Blocks: 24         IO Block: 4096   regular file<br />
Device: fd03h/64771d    Inode: 913307      Links: 1<br />
Access: (4777/-<span style="text-decoration: underline;"><strong>rws</strong></span>rwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)<br />
Access: 2008-11-13 01:46:20.000000000 -0800<br />
Modify: 2008-11-13 01:44:12.000000000 -0800<br />
Change: 2008-11-13 01:53:01.000000000 -0800</span></p>
<p>Oh. My. God. This binary has the suid bit set! And it's owned by root! This could be bad...</p>
<p>Let's run <span style="color: #00ffff;"><em>strings /var/www/a.out</em></span> and see what kind of info we can dig out of this binary:</p>
<p style="padding-left: 30px;"><span style="color: #008000;">linux:~# strings /var/www/a.out<br />
/lib64/ld-linux-x86-64.so.2<br />
__gmon_start__<br />
libc.so.6<br />
puts<br />
__libc_start_main<br />
GLIBC_2.2.5<br />
ATUS<br />
[]A\<br />
<strong>hello world!</strong></span></p>
<p>Whew! So some hacker just put a simple &#8220;hello world&#8221; program in your web server root. I guess you can relax now&#8230; or can you? I wouldn&#8217;t just yet&#8230;</p>
<p>I&#8217;d start by searching for other files with the suid bit set, and then either change their permissions if needed, or delete them. I think it&#8217;s safe to say that binaries located outside of your cgi-enabled directories can be safely removed&#8211;unless you&#8217;re hosting downloads. You might use the following command (from within /var/www) to find suid-enabled files:</p>
<p style="padding-left: 30px;"><span style="color: #008000;">find -type f -perm /u+s </span></p>
<p>Or this variant will work if you&#8217;re sure you don&#8217;t need suid capabilities.</p>
<p style="padding-left: 30px;"><span style="color: #008000;">find -type f -perm /u+s | xargs chmod 0644</span></p>
<p>Generally, unless there&#8217;s a *very* specific reason for it, no binary should be suid root. Many Unix and Linux distributions will have a small handful of suid files, however. So don&#8217;t go deleting and chmod&#8217;ing things unless you&#8217;re sure it&#8217;s not needed.</p>
<p>On a final note, I&#8217;d like to mention that there are a great many commands available to the linux/unix sysadmin. Don&#8217;t worry about mastering every one of them, since this could very well drive you mad. Just try them as you go, and develop a style of your own. Consider this: While it may be more elegant to use 3 more advanced commands to perform a task, if 5 commands come faster to you, then you will probably have greater efficiency executing those 5 commands. With experience, you&#8217;ll modify your style and adopt new variations of commands as needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.on-tap.org/2008/11/13/unix-linux-oft-forgotten-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
