<?xml version="1.0" encoding="iso-8859-1"?>

<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title type="text">The Wandering Geek</title>
<subtitle type="html"><![CDATA[
Linux and Unix Sysadmin, Coding and Hacks
]]></subtitle>
<id>http://blog.unixlore.net/index.cgi/index.atom</id>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi" />
<link rel="self" type="application/atom+xml" href="http://blog.unixlore.net/index.cgi/index.atom" />


<author>
<name>Doug</name>
<uri>http://blog.unixlore.net/index.cgi/index.atom</uri>
<email>doug_at_unixlore_dot_net</email>
</author>
<rights>Copyright 2009 doug_at_unixlore_dot_net</rights>
<generator uri="http://pyblosxom.sourceforge.net/" version="1.4.3 01/10/2008">
PyBlosxom http://pyblosxom.sourceforge.net/ 1.4.3 01/10/2008
</generator>

<updated>2009-10-02T04:04:00Z</updated>
<!-- icon?  logo?  -->

<entry>
<title type="html">Killing Processes by Name on Linux or Unix Systems</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/10/02/killing-processes-by-name-on-linux-or-unix-systems</id>
<updated>2009-10-02T04:04:00Z</updated>
<published>2009-10-02T04:04:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/killing-processes-by-name-on-linux-or-unix-systems.html" />
<content type="html">
&lt;p&gt;
Finding and killing a process on a Unix or Linux system is typically
done by sending it a signal using
the &lt;span style=&quot;font-style:italic;&quot;&gt;kill&lt;/span&gt; command, specifying
the process ID (PID), which we can grab using
&lt;span style=&quot;font-style:italic;&quot;&gt;ps&lt;/span&gt;
and &lt;span style=&quot;font-style:italic;&quot;&gt;grep&lt;/span&gt;
(use &lt;span style=&quot;font-style:italic;&quot;&gt;ps -ef&lt;/span&gt; on Solaris):
&lt;/p&gt;

&lt;code&gt;
dmaxwell@kaylee:~$ ps ax | grep gedit
11604 ?        Sl     0:01 gedit
11609 pts/5    S+     0:00 grep gedit
dmaxwell@kaylee:~$ kill 11604
&lt;/code&gt;

&lt;p&gt;
But it&amp;#8217;s sometimes convenient to want to kill a running process by
name, or kill a group of running processes with the same name. The
most portable way to do this is with
the &lt;span style=&quot;font-style:italic;&quot;&gt;pkill&lt;/span&gt; command - this is
present on most Linux, Solaris and BSD systems. The simplest way to
use pkill is just to specify the process name:
&lt;/p&gt;

&lt;code&gt;
pkill gedit
&lt;/code&gt;

&lt;p&gt;
This sends a TERM signal to any process whose name matches &amp;#8216;gedit&amp;#8217;,
terminating it. If you have a long-running command and can only
remember part of the command string, no problem -
use &lt;span style=&quot;font-style:italic;&quot;&gt;-f&lt;/span&gt; with pkill:
&lt;/p&gt;

&lt;code&gt;
dmaxwell@kaylee:~$ ps ax | grep name
11902 pts/5    S      5:23 find . -name foo*
11906 pts/5    S+     0:00 grep name
dmaxwell@kaylee:~$ pkill -f name
&lt;/code&gt;

&lt;p&gt;
This would kill the find process (and the grep if it were still
running), since part of its full command string contained the
substring &amp;#8216;name&amp;#8217;. Using pkill in this way will by default gracefully
terminate processes, but for stubborn processes that refuse to die,
you can specify a different signal. Here we specify a KILL signal,
which immediately ends a process.
&lt;/p&gt;

&lt;code&gt;
pkill -KILL name
&lt;/code&gt;

&lt;p&gt;
You can use numeric signals in place of the signal name, for example
&amp;#8216;-9&amp;#8242; is the KILL signal in the last example.
&lt;/p&gt;

&lt;p&gt;
Killing a group of processes is just as easy. Sometimes this is
necessary when system shutdown scripts fail, perhaps due to a missing
lockfile. Here we kill all the Apache processes running on our server
after the shutdown command fails:
&lt;/p&gt;

&lt;code&gt;
root@kaylee:~# /etc/init.d/apache2 stop
 * Stopping web server apache2                                                                                                                                                                          [ OK ] 
root@kaylee:~# ps ax | grep apache
13124 ?        Ss     0:00 /usr/sbin/apache2 -k start
13129 ?        S      0:00 /usr/sbin/apache2 -k start
13130 ?        S      0:00 /usr/sbin/apache2 -k start
13131 ?        S      0:00 /usr/sbin/apache2 -k start
13132 ?        S      0:00 /usr/sbin/apache2 -k start
13133 ?        S      0:00 /usr/sbin/apache2 -k start
13162 pts/8    S+     0:00 grep apache
root@kaylee:~# pkill apache
root@kaylee:~# ps ax | grep apache
13165 pts/8    S+     0:00 grep apache
root@kaylee:~#
&lt;/code&gt;

&lt;p&gt;
Using &lt;span style=&quot;font-style:italic;&quot;&gt;pkill -f start&lt;/span&gt; would
also work here, since each of the Apache command lines contains the
substring &amp;#8217;start&amp;#8217;. The pkill command has many more options, but one
other that might be useful
is &lt;span style=&quot;font-style:italic;&quot;&gt;-u&lt;/span&gt;, which will allow you to
specify a username or ID. In this example we send a TERM signal to all
the processes owned by the user &amp;#8216;nobody&amp;#8217;:
&lt;/p&gt;

&lt;code&gt;
root@kaylee:~# pkill -u nobody
&lt;/code&gt;

&lt;p&gt;
There is a sister command to
pkill, &lt;span style=&quot;font-style:italic;&quot;&gt;pgrep&lt;/span&gt;, that takes most
of the same options but rather than sending a signal to one or a group
of processes, it just displays the process IDs. This can be fed as
standard input into other commands. Here is an example:


&lt;code&gt;
dmaxwell@kaylee:~$ pgrep -d, apache2
14507,14512,14513,14514,14515,14516

dmaxwell@kaylee:~$ ps fvp $(pgrep -d, apache2)
  PID TTY      STAT   TIME ..  RSS %MEM COMMAND
14507 ?        Ss     0:00 .. 11076  0.3 /usr/sbin/apache2 -k start
14512 ?        S      0:00 .. 6032  0.2  \_ /usr/sbin/apache2 -k start
14513 ?        S      0:00 .. 6028  0.2  \_ /usr/sbin/apache2 -k start
14514 ?        S      0:00 .. 6028  0.2  \_ /usr/sbin/apache2 -k start
14515 ?        S      0:00 .. 6028  0.2  \_ /usr/sbin/apache2 -k start
14516 ?        S      0:00 .. 6028  0.2  \_ /usr/sbin/apache2 -k start
&lt;/code&gt;

&lt;p&gt;
This is particularly useful, since it preserves the header line output
by ps, as opposed to something
like &lt;span style=&quot;font-style:italic;&quot;&gt;ps avx | grep apache&lt;/span&gt;,
which displays the data, but not the column headers. Both pkill and
pgrep are documented in the same manual page, so search for either in
the &lt;a href=&quot;http://www.freebsd.org/cgi/man.cgi&quot;&gt;FreeBSD&lt;/a&gt;
or &lt;a href=&quot;http://manpages.debian.net/cgi-bin/man.cgi&quot;&gt;Debian&lt;/a&gt; man
pages for more info.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Quick Log File Processing with Perl</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/09/14/quick-log-file-processing-with-perl</id>
<updated>2009-09-15T01:20:00Z</updated>
<published>2009-09-15T01:20:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/quick-log-file-processing-with-perl.html" />
<content type="html">
&lt;p&gt;
A common thing to want to do as a sysadmin is match and print text
from a file in a particular output format. There are lots of ways to
do this using shell tools - grep, sed and awk are used frequently -
but I&amp;#8217;d like to show you a common Perl idiom for doing this type of
task.
&lt;/p&gt;

&lt;p&gt; &lt;a href=&quot;http://perl.org&quot;&gt;Perl&lt;/a&gt; was originally designed to be a
replacement for the various shell tools, and while it has grown into
much more over the years, it is still a great tool to have in your
command line toolbox. Here&amp;#8217;s an example. Let&amp;#8217;s say you want to print the date, time,
IP address and URL each time your website is crawled by a
Googlebot. The Apache access log will look something like this: &lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
...
10.249.66.234 - - [12/Sep/2009:19:22:51 -0400] &quot;GET /robots.txt HTTP/1.1&quot; 404 424 &quot;-&quot; &quot;Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)&quot;
10.249.66.234 - - [12/Sep/2009:19:22:51 -0400] &quot;GET / HTTP/1.1&quot; 200 - &quot;-&quot; &quot;Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)&quot;
...
&lt;/code&gt;

&lt;p&gt; A quick solution is this, all in one line:&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
serenity:~# perl -wnle &apos;print &quot;Googlebot accessed \&quot;$4\&quot; from $1 on $2 at $3&quot; if (/^ (\d+\.\d+\.\d+\.\d+) .+? \[ (.+?) : (.+?) \s .+? GET\s+(.+?)\s+HTTP .+ Googlebot/x)&apos; /var/log/apache2/access.log
Googlebot accessed &quot;/robots.txt&quot; from 10.249.66.234 on 12/Sep/2009 at 19:22:51
Googlebot accessed &quot;/&quot; from 10.249.66.234 on 12/Sep/2009 at 19:22:51
serenity:~#
&lt;/code&gt;

&lt;p&gt;
There are four command line options used here:

&lt;ul&gt;
&lt;li&gt;w: Turn on warnings&lt;/li&gt;
&lt;li&gt;n: Loop through the supplied file one line at a time&lt;/li&gt;
&lt;li&gt;l: Print a newline after each line of output&lt;/li&gt;
&lt;li&gt;e: Execute the Perl code that follows&lt;/li&gt;
&lt;/ul&gt;

See the &lt;a href=&quot;http://perldoc.perl.org/perlrun.html&quot;&gt;perlrun
manpage&lt;/a&gt; for details, there is much more to Perl&amp;#8217;s command line
processing.
&lt;/p&gt;

&lt;p&gt; I build the regular expression by picking a target line and going
through it from left to right, adding expressions as I go. I make use
of the /x modifier so that it is easier to read - this makes Perl
ignore whitespace in the regexp. I also use Perl&amp;#8217;s non-greedy
quantifier quite a bit, this is the question mark in expressions like
&lt;code&gt;.+?  \[&lt;/code&gt;. This little snippet matches one or more of any
character, followed by a left-bracket. The question mark ensures that
the &lt;span style=&quot;font-style:italic;&quot;&gt;first&lt;/span&gt; such left-bracket is
matched. Normally Perl&amp;#8217;s regexp engine would happily chomp away at
characters and match the &lt;span style=&quot;font-style:italic;&quot;&gt;last&lt;/span&gt;
left bracket it found in the line. Using the greedy form &lt;code&gt;.+ \[&lt;/code&gt; 
would work for us, since there is only one such left bracket
in each line, but it turns out to be a performance improvement if we
are parsing large text files (For more info, I encourage you to read
&lt;a
href=&quot;http://www.amazon.com/gp/product/0596528124?ie=UTF8&amp;#038;tag=gepi0f-20&amp;#038;linkCode=as2&amp;#038;camp=1789&amp;#038;creative=9325&amp;#038;creativeASIN=0596528124&quot;&gt;Mastering
Regular Expressions&lt;/a&gt; by Jeffrey Friedl, or start with the &lt;a
href=&quot;http://perldoc.perl.org/perlretut.html&quot;&gt;Regular Expression
Tutorial&lt;/a&gt;).  &lt;/p&gt;

&lt;p&gt;
This method has a few advantages. For one, it relies on just one tool,
not a few disparate ones. Perl is portable to many operating systems,
so you could use this to parse text files on Windows, for example. You
also have the ability to load modules on the command line with the
&amp;#8216;-M&amp;#8217; switch. This gives you access to all
of &lt;a href=&quot;http://www.cpan.org&quot;&gt;CPAN&lt;/a&gt;, potentially a huge
time-saver.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Troubleshooting SSH Connections</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/09/02/troubleshooting-ssh-connections</id>
<updated>2009-09-03T02:17:00Z</updated>
<published>2009-09-03T02:17:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/troubleshooting-ssh-connections.html" />
<content type="html">
&lt;p&gt;
I&amp;#8217;ve helped a few people recently who have had trouble
getting &lt;a href=&quot;http://openssh.com&quot;&gt;OpenSSH&lt;/a&gt; working properly;
I&amp;#8217;ve also had my share of issues over the years. Generally problems
with SSH connections fall into two groups - network related and server
related. Most of these problems can be fixed fairly quickly if you
know what to look for.
&lt;/p&gt;

&lt;h2&gt;Network Related&lt;/h2&gt;

&lt;p&gt;
These will typically be caused by improper routing or firewall
configurations. Here are some things to check.
&lt;/p&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;1.&lt;/span&gt; If your SSH server sits
behind a firewall or router, make sure the default route of your
internal SSH server points back to that firewall or router. Seems
obvious, but it&amp;#8217;s common to forget about the return trip packets need
to make. This will display your default gateway:
&lt;/p&gt;

&lt;code&gt;
netstat -rn | grep &apos;^0&apos;
&lt;/code&gt;

&lt;p&gt;
Sometimes the default gateway is just one of your server interfaces,
this is OK as long as that interface is directly connected to
something that knows how to get back to your client.
&lt;/p&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;2.&lt;/span&gt; While you&amp;#8217;re at it, make
sure the incoming SSH packets are actually getting to your SSH
server. &lt;a href=&quot;http://www.tcpdump.org/tcpdump_man.html&quot;&gt;Tcpdump&lt;/a&gt;
works very nicely for this, you&amp;#8217;ll need to be root to run it on the
server:
&lt;/p&gt;

&lt;code&gt;
tcpdump -n -i eth0 tcp port 22 and host [IP address of client]
&lt;/code&gt;

&lt;p&gt;
Just replace &lt;span style=&quot;font-style:italic;&quot;&gt;eth0&lt;/span&gt; by your
client-facing interface name. If you don&amp;#8217;t see incoming SSH packets
during connection attempts, it&amp;#8217;s probably due to a firewall or router
access list.
&lt;/p&gt;

&lt;h2&gt;SSH Server Problems&lt;/h2&gt;

&lt;p&gt;
All of these issues revolve around SSH server configuration settings -
not misconfigurations necessarily, just settings you may not be aware
of.
&lt;/p&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;1.&lt;/span&gt; Permissions can be a problem
- in its default configuration, OpenSSH
sets &lt;span style=&quot;font-weight:bold;&quot;&gt;StrictModes&lt;/span&gt;
to &lt;span style=&quot;font-weight:bold;&quot;&gt;yes&lt;/span&gt; and won&amp;#8217;t allow any
connections if the account you&amp;#8217;re trying to SSH into has group- or
world-writable permissions on its home
directory, &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh&lt;/span&gt; directory,
or &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh/authorized_keys&lt;/span&gt;
file. I typically just make the two directories mode 700 and the
authorized_keys file mode 600. The sshd man page suggests this
one-liner:
&lt;/p&gt;

&lt;code&gt;
chmod go-w ~/ ~/.ssh ~/.ssh/authorized_keys
&lt;/code&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;2.&lt;/span&gt; On Debian or Ubuntu systems,
it is possible the keys you are using to connect are blacklisted.
This is only an issue on Debian or Debian-based clients, and stems
from this &lt;a href=&quot;http://www.debian.org/security/2008/dsa-1576&quot;&gt;
now-famous vulnerability in May of 2008&lt;/a&gt;. To detect any such
blacklisted keys,
run &lt;span style=&quot;font-style:italic;&quot;&gt;ssh-vulnkey&lt;/span&gt; on the client,
while logged into the account you are connecting from. Debian and
Ubuntu SSH servers will reject any such keys unless
the &lt;span style=&quot;font-weight:bold;&quot;&gt;PermitBlacklistedKeys&lt;/span&gt;
directive in
the &lt;span style=&quot;font-style:italic;&quot;&gt;/etc/ssh/sshd_config&lt;/span&gt; file
is set to &lt;span style=&quot;font-weight:bold;&quot;&gt;no&lt;/span&gt;. I don&amp;#8217;t recommend
you actually leave this security check disabled, but it can be useful
to temporarily disable it during testing.
&lt;/p&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;3.&lt;/span&gt; Finally, if all else fails,
you can see exactly what the SSH server is doing by running it in
debug mode on a non-standard port:
&lt;/p&gt;

&lt;code&gt;
/usr/sbin/sshd -d -p 2222
&lt;/code&gt;

&lt;p&gt;Then, on the client, connect and watch the server output:&lt;/p&gt;

&lt;code&gt;
ssh -vv -p 2222 [Server IP]
&lt;/code&gt;

&lt;p&gt;
Note the &lt;span style=&quot;font-style:italic;&quot;&gt;-vv&lt;/span&gt; option to provide
verbose client output. This alone can sometimes help debug connection
issues.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Move Over, Grep. Hello, Ack</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/08/23/move-over-grep-hello-ack</id>
<updated>2009-08-23T23:20:00Z</updated>
<published>2009-08-23T23:20:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/move-over-grep-hello-ack.html" />
<content type="html">
&lt;p&gt;
As someone who has been using grep and its variants like egrep for
years, I admit they have been insanely useful. But every once in a
while something comes along that improves an idea so much, you can&amp;#8217;t
ignore it. Such a thing
is &lt;a href=&quot;http://betterthangrep.com/&quot;&gt;Ack&lt;/a&gt;, the grep replacement.
&lt;/p&gt;

&lt;p&gt;
I do a lot of software development in large codebases, and the ability
to find snippets of text is paramount. Tags can be used and integrated
with Emacs (or Vim, we&amp;#8217;re not all perfect), which is great for
function names, but not useful for general text searches. Using grep
in a code repository is a pain, and usually means some sort of hack to
ignore VC directories
like &lt;span style=&quot;font-style:italic;&quot;&gt;.svn&lt;/span&gt;
and &lt;span style=&quot;font-style:italic;&quot;&gt;RCS&lt;/span&gt;. Enter &lt;span style=&quot;font-style:italic;&quot;&gt;ack&lt;/span&gt;
- similar to grep but with some more thought behind it. It ignores VC
meta-data directories by default and is written in pure Perl - so it&amp;#8217;s
portable and supports the full Perl regexp syntax. Having a pure-Perl
version available with no dependencies also means its easy to install
in shared hosting environments, where you don&amp;#8217;t have root access.
&lt;/p&gt;

&lt;p&gt; Install ack by
just &lt;a href=&quot;http://betterthangrep.com/ack-standalone&quot;&gt;downloading
the standalone version&lt;/a&gt; and put it in your command path, use CPAN
(&lt;span style=&quot;font-style:italic;&quot;&gt;cpan App::Ack&lt;/span&gt;), or install a
pre-packaged binary (On Debian/Ubuntu systems, the package name
is &lt;span style=&quot;font-style:italic;&quot;&gt;ack-grep&lt;/span&gt;). Ack output is
very readable, with highlighted matches by default as well as line
numbers and file names. Here is an example:
&lt;/p&gt;

&lt;br /&gt;

&lt;code&gt;
dmaxwell@kaylee:~/tmp$ ack-grep -ai &apos;limit_as.+?\&amp;#038;rlimit&apos; emacs-22.3
emacs-22.3/src/vm-limit.c
76:  getrlimit (RLIMIT_AS, &amp;#038;rlimit);
&lt;/code&gt;

&lt;br /&gt;&lt;br /&gt;

Here is a screenshot so you can see the highlighting and colorization:

&lt;p&gt;
&lt;img src=&quot;/images/ack.png&quot; alt=&quot;Ack usage and output&quot;&gt;
&lt;/p&gt;

&lt;p&gt;
The &lt;span style=&quot;font-style:italic;&quot;&gt;-ai&lt;/span&gt; means &amp;#8217;search all,
case insensitively&amp;#8217;, and tells Ack to search all filetypes (but still
not including common VCS directories or files), while ignoring
case. Ack searches are recursive by default, so there is no need for
a &lt;span style=&quot;font-style:italic;&quot;&gt;-r&lt;/span&gt; switch. You can see we
used Perl&amp;#8217;s non-greedy match quantifier in the search regexp,
something egrep can&amp;#8217;t do. This speeds the search up considerably.
&lt;/p&gt;

&lt;p&gt;
There is much more to ack, &lt;a href=&quot;http://betterthangrep.com/&quot;&gt;read
the docs&lt;/a&gt; and give it a try. I hope you&amp;#8217;ll find it as useful as I
have.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Five Minutes to an Even More Secure SSH</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/08/16/five-minutes-to-more-secure-ssh</id>
<updated>2009-08-16T12:42:00Z</updated>
<published>2009-08-16T12:42:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/five-minutes-to-more-secure-ssh.html" />
<content type="html">
&lt;a href=&quot;http://openssh.com&quot;&gt;&lt;img align=&quot;right&quot; alt=&quot;OpenSSH&quot; src=&quot;/images/openssh.gif&quot;/&gt;&lt;/a&gt;

&lt;p&gt;
One of the most popular articles on this blog
was &lt;a href=&quot;http://blog.unixlore.net/2006/04/five-minutes-to-more-secure-ssh.html&quot;&gt;Five-Minutes
to a More Secure SSH&lt;/a&gt;. My impetus for writing it was seeing too
many client&amp;#8217;s servers left in a default state where they are
vulnerable to brute-force attacks. In it, I basically advocate three
things:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disabling password authentication&lt;/li&gt;
&lt;li&gt;Disabling root login&lt;/li&gt;
&lt;li&gt;Enabling key-based authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Three years later, those recommendations still hold true and I would
encourage you to follow them. However, OpenSSH has many features and
there is more you can do to secure your SSH servers, without resorting
to external software.
&lt;/p&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;Important Notes:&lt;/span&gt; The main
OpenSSH server configuration file is
called &lt;span style=&quot;font-style:italic;&quot;&gt;sshd_config&lt;/span&gt; and will
typically be in the &lt;span style=&quot;font-style:italic;&quot;&gt;/etc/ssh&lt;/span&gt;
or &lt;span style=&quot;font-style:italic;&quot;&gt;/etc/sshd&lt;/span&gt; directories. Like
all of the configuration files used by OpenSSH, it is in plain text
and so can be edited with
any &lt;a href=&quot;http://www.gnu.org/software/emacs/&quot;&gt;text
editor&lt;/a&gt;. After editing
your &lt;span style=&quot;font-style:italic;&quot;&gt;sshd_config&lt;/span&gt; file, you
will need to reload your SSH server&amp;#8217;s configuration - restarting the
SSH daemon is not necessary. The command typically looks like this
(this is on Debian or Ubuntu):

&lt;code&gt;
/etc/init.d/ssh reload
&lt;/code&gt;

or (on Red Hat/Fedora):

&lt;code&gt;
service sshd reload
&lt;/code&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;Also be careful not to lock yourself
out of your SSH server when experimenting with these access
controls&lt;/span&gt;. It&amp;#8217;s a good idea to always have two SSH sessions into
the server, and to always make backup of the relevant configuration
files. If you log out of one session and get denied access, you still
have one active session to fix things.
&lt;/p&gt;

&lt;h2&gt;Restricting Users and Hosts&lt;/h2&gt;

&lt;p&gt;
OpenSSH allows you to restrict users and groups by host or IP
address. There are four different directives you can use in
your &lt;span style=&quot;font-style:italic;&quot;&gt;sshd_config&lt;/span&gt; file (they
are evaluated in this order):
&lt;/p&gt;

&lt;code&gt;
DenyUsers
AllowUsers
DenyGroups
AllowGroups
&lt;/code&gt;

&lt;p&gt;
The format for all of them will be the same - a space-separated list
of users or group names, with optional host names. Here is an example:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
AllowUsers vader@10.0.0.1 maul@sproing.evillittleman.net sidious tyranus@*.evillitleman.net
AllowGroups wheel staff
&lt;/code&gt;

&lt;p&gt;
This tells sshd to only allow connections from the
user &lt;span style=&quot;font-style:italic;&quot;&gt;vader&lt;/span&gt; and only from the
IP address &lt;span style=&quot;font-style:italic;&quot;&gt;10.0.0.1&lt;/span&gt;. The
user &lt;span style=&quot;font-style:italic;&quot;&gt;maul&lt;/span&gt; is also allowed, but
only from the host
&lt;span style=&quot;font-style:italic;&quot;&gt;sproing.evillittleman.net&lt;/span&gt;. User &lt;span style=&quot;font-style:italic;&quot;&gt;sidious&lt;/span&gt;
is allowed from anywhere, and the
user &lt;span style=&quot;font-style:italic;&quot;&gt;tyranus&lt;/span&gt; is also allowed,
from any host in
the &lt;span style=&quot;font-style:italic;&quot;&gt;evillittleman.net&lt;/span&gt; domain
(the asterisk matches zero or more characters).
&lt;/p&gt;

&lt;p&gt;
The &lt;span style=&quot;font-style:italic;&quot;&gt;AllowGroups&lt;/span&gt; line allows
login only from users whose primary group name or supplementary group
list match one of &amp;#8216;wheel&amp;#8217; or &amp;#8217;staff&amp;#8217;.
&lt;/p&gt;

&lt;p&gt;
Keep in mind that
using &lt;span style=&quot;font-style:italic;&quot;&gt;AllowUsers&lt;/span&gt;
or &lt;span style=&quot;font-style:italic;&quot;&gt;AllowGroups&lt;/span&gt; means that
anyone not matching one of the supplied patterns will be denied access
by default. Also, in order for sshd to allow access based on full or
partial hostnames, it needs to do a DNS lookup on the incoming IP
address. That means the connecting IP address must have a PTR
(reverse) entry that maps back to a real hostname. These aren&amp;#8217;t hard
to get if you have a static IP address, usually your ISP or server
hosting provider can do this for you on request. If your server is
internal, you probably have your own DNS server and can add
appropriate PTR entries yourself.
&lt;/p&gt;

&lt;p&gt;
In addition to the asterisk in hostname or group patterns, you can use
a question-mark to mean exactly one character, and an exclamation
point to negate the sense of a match:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;*&lt;/span&gt; - Matches zero or more characters
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;?&lt;/span&gt; - Matches exactly one character
&lt;br /&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;!&lt;/span&gt; - Negates the host pattern match
&lt;/blockquote&gt;

&lt;p&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;Note:&lt;/span&gt; In my tests,
using &lt;span style=&quot;font-style:italic;&quot;&gt;!&lt;/span&gt; to negate the sense of
the hostname match did not work with
the &lt;span style=&quot;font-style:italic;&quot;&gt;AllowUsers&lt;/span&gt; directive. It
only seems to work when used
with &lt;span style=&quot;font-style:italic;&quot;&gt;authorized_keys&lt;/span&gt; file
restrictions (see below).
&lt;/p&gt;

&lt;h2&gt;Restricting Access and Commands&lt;/h2&gt;

&lt;p&gt;
SSH has the concept of &lt;span style=&quot;font-style:italic;&quot;&gt;authorized
keys&lt;/span&gt;. If you are using key-based auth, like I suggested in
my &lt;a href=&quot;http://blog.unixlore.net/2006/04/five-minutes-to-more-secure-ssh.html&quot;&gt;first
article&lt;/a&gt;, the user accounts on the SSH server will have
an &lt;span style=&quot;font-style:italic;&quot;&gt;authorized_keys&lt;/span&gt; file (which
is by default in the &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh&lt;/span&gt;
directory of whatever user account you are logging into). This file
lists the public keys, one per line, that are authorized for access to
that account. Apart from just specifying which public keys are allowed
access, there are a some more options that you can use to further
restrict SSH sessions. Here are the most useful ones:
&lt;/p&gt;

&lt;blockquote&gt;
  &lt;span style=&quot;font-weight:bold;&quot;&gt;from=&amp;#8221;hostname1,hostname2,&amp;#8230;&amp;#8221;&lt;/span&gt; - Restricts access from the specified IP or hostname patterns
  &lt;br /&gt;
  &lt;span style=&quot;font-weight:bold;&quot;&gt;command=&amp;#8221;command&amp;#8221;&lt;/span&gt; - Runs the specified command after authentication
  &lt;br /&gt;
  &lt;span style=&quot;font-weight:bold;&quot;&gt;no-pty&lt;/span&gt; - Does not allocate a pty (does not allow interactive login)
  &lt;br /&gt;
  &lt;span style=&quot;font-weight:bold;&quot;&gt;no-port-forwarding&lt;/span&gt; - Does not allow port forwarding
&lt;/blockquote&gt;

&lt;p&gt;
Here is an example showing part of
an &lt;span style=&quot;font-style:italic;&quot;&gt;authorized_keys&lt;/span&gt; file:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
from=&quot;deathstar.example.com,!jedi.example.com,10.0.0.?&quot; ssh-rsa AAAAB5...2BQ== vader@evillittleman.net
from=&quot;pitofdespair.example.com&quot;,command=&quot;ls&quot;,no-pty,no-port-forwarding ssh-dss AAAAZ7...22Q== droidQBX12@evillittleman.net 
&lt;/code&gt;

&lt;p&gt;
The first line allows login with the specified RSA key from
&lt;span style=&quot;font-style:italic;&quot;&gt;deathstar.example.com&lt;/span&gt;, from
any host with IP address in 10.0.0.[0-9], but not from the
host &lt;span style=&quot;font-style:italic;&quot;&gt;jedi.example.com&lt;/span&gt;. The
second line merely runs the &amp;#8216;ls&amp;#8217; command whenever the specified DSA
key is used - it does not allow any other commands to be run, does not
allow interactive login, and does not allow port-forwarding. It also
restricts the source of that key to the
host &lt;span style=&quot;font-style:italic;&quot;&gt;pitofdespair.example.com&lt;/span&gt;.
&lt;/p&gt;

&lt;h2&gt;Running sshd on a Non-Standard Port&lt;/h2&gt;

&lt;p&gt;
Admittedly this is an attempt at &amp;#8217;security through obscurity&amp;#8217;, but
that doesn&amp;#8217;t mean it&amp;#8217;s not useful when combined with other security
measures. You may not be able to restrict access by hostname or IP,
for example - you may always be sourcing your connections from a
dynamic IP address, or you may not be able to get a proper PTR record
created. It&amp;#8217;s also very easy to do. In
your &lt;span style=&quot;font-style:italic;&quot;&gt;sshd_config&lt;/span&gt; file, just
change &lt;span style=&quot;font-style:italic;&quot;&gt;Port=22&lt;/span&gt;
to &lt;span style=&quot;font-style:italic;&quot;&gt;Port=nnnnn&lt;/span&gt;
(where &lt;span style=&quot;font-style:italic;&quot;&gt;nnnnn&lt;/span&gt; is some high
port), then reload the sshd configuration. How do we pick a port
number? Some &lt;span style=&quot;font-weight:bold;&quot;&gt;are&lt;/span&gt; better than
others. First, assume that most port scans are being done
with &lt;a href=&quot;http://nmap.org&quot;&gt;Nmap&lt;/a&gt;, and take a look at
the &lt;a href=&quot;http://nmap.org/svn/nmap-services&quot;&gt;nmap-services&lt;/a&gt;
file. This is a list of ports that Nmap will use by default if you
don&amp;#8217;t specify a port range on the command line. It&amp;#8217;s probably a fair
bet that most script-kiddies are using nmap is this manner. Just pick
a high port not on this list, most nmap scans won&amp;#8217;t notice it. You can
also use multiple &lt;span style=&quot;font-style:italic;&quot;&gt;Port=&lt;/span&gt;
directives, meaning you can have sshd listen on multiple
ports. Connecting to an alternate port is also very easy, use the
following options depending on the command used:
&lt;/p&gt;

&lt;code&gt;
ssh -p 65502 vader@deathstar.example.com
sftp -oPort=65502 vader@deathstar.example.com
scp -P 65502 deathstar_plans.doc vader@deathstar.example.com:
&lt;/code&gt;

&lt;p&gt;
You can also edit
your &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh/config&lt;/span&gt; file, and
add the &lt;span style=&quot;font-style:italic;&quot;&gt;Port=&lt;/span&gt; directive to one
of your host blocks:
&lt;/p&gt;

&lt;code&gt;
...
Host    evil
        Hostname deathstar.example.com
        User vader
        Port 65502
...
&lt;/code&gt;

&lt;p&gt;
Then just connecting with the
command &lt;span style=&quot;font-style:italic;&quot;&gt;ssh evil&lt;/span&gt; will connect
with the specified user and port.
&lt;/p&gt;

&lt;h2&gt;Hashing Known Hosts Files&lt;/h2&gt;

&lt;p&gt;
When you connect to an SSH server, the ssh client stores the server&amp;#8217;s
hostname, IP address and host key in a file
named &lt;span style=&quot;font-style:italic;&quot;&gt;known_hosts&lt;/span&gt;. It will by
default be in your &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh&lt;/span&gt;
directory. Having the IP addresses of the servers you connect to
regularly in plaintext can be a security risk if you are on a shared
host, or your client gets compromised (stolen laptop, for example). An
easy way to avoid this problem is to obscure the information in the
&lt;span style=&quot;font-style:italic;&quot;&gt;known_hosts&lt;/span&gt; file
by &lt;a href=&quot;http://en.wikipedia.org/wiki/Cryptographic_hash_function&quot;&gt;hashing&lt;/a&gt;
it. Hashing your &lt;span style=&quot;font-style:italic;&quot;&gt;known_hosts&lt;/span&gt;
file is easy, you just use
the &lt;span style=&quot;font-style:italic;&quot;&gt;ssh-keygen&lt;/span&gt; command, giving
it the file path.
&lt;/p&gt;

&lt;code&gt;
ssh-keygen -H -f ~/.ssh/known_hosts
&lt;/code&gt;

&lt;p&gt;
While this hashes all existing host keys, any host keys that get added
to your &lt;span style=&quot;font-style:italic;&quot;&gt;known_hosts&lt;/span&gt; file after
you hash it do &lt;span style=&quot;font-weight:bold;&quot;&gt;not&lt;/span&gt; get hashed
by default. To make it the default, add the
directive &lt;span style=&quot;font-style:italic;&quot;&gt;HashKnownHosts&lt;/span&gt; to
your &lt;span style=&quot;font-style:italic;&quot;&gt;~/.ssh/config&lt;/span&gt; file. Here
is an example of hashing
a &lt;span style=&quot;font-style:italic;&quot;&gt;known_hosts&lt;/span&gt; file. First,
here is what the file looks like beforehand:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
dmaxwell@kaylee:~/.ssh$ head known_hosts
10.100.6.151 ssh-rsa AAAAB4NzaC1yc2EAAAABIwAAAIEAuVgRdptT3xsQoGkiNnJb4Zb02p07MaZX02MFs5JhoqmvV5X5Z/LEQH0S7ngSn3b8kQUnocGulJgLchwfThrd/1OkdyOKdpgXxH/rmDXfwh/MZBNBxnMWBa1HpXSc1gxyDfSSxo+VPa1NCP+ob0dWx4sI+JFJ5cVzbQng4rKp3x8=
10.100.6.162 ssh-rsa AAAAB4NzaC1yc2EAAAABIwAAAIEAxpQuMJR4Dq/MmrpUryYlNbP+BIWgJlr0LAfaHTIU64Ho6F58Bb1QzlUeeHQSI9f6qFW9aPsBC3Gd5wgQBUj3byinXXHC/10c3vmb2aEujmyL6en2Pef4AN8bKgaRtJq2G/H4MkPWBzxqZPb/k9c3a26P/DjG4y01TMw9vCld+As=
...
&lt;/code&gt;

&lt;p&gt;
Here we run the &lt;span style=&quot;font-style:italic;&quot;&gt;ssh-keygen&lt;/span&gt; command:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
dmaxwell@kaylee:~/.ssh$ ssh-keygen -H -f ~/.ssh/known_hosts
/home/dmaxwell/.ssh/known_hosts updated.
Original contents retained as /home/dmaxwell/.ssh/known_hosts.old
WARNING: /home/dmaxwell/.ssh/known_hosts.old contains unhashed entries
Delete this file to ensure privacy of hostnames
&lt;/code&gt;

&lt;p&gt;
And here is what the file looks like afterward (Note that we deleted
the backup file when we were done):
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
dmaxwell@kaylee:~/.ssh$ head known_hosts
|1|PdThGCuhg23t9bcURxyitJTmfKk=|/z+Xvh4xPuDni8PTB5iK7KKnGdA= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAuVgRdptT3xsQoGkiNnJb4Zb02p07MaZX02MFs5JhoqmvV5X5Z/LEQH0S7ngSn3b8kQUnocGulJgLchwfThrd/1OkdyOKdpgXxH/rmDXfwh/MZBNBxnMWBa1HpXSc1gxyDfSSxo+VPa1NCP+ob0dWx4sI+JFJ5cVzbQng4rKp3x8=
|1|vkLZ22nl30gyJ3gIX74FUF7b3eg=|uy5oSZ8avgZQZE+dwMd/mXGoA38= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAxpQuMJR4Dq/MmrpUryYlNbP+BIWgJlr0LAfaHTIU64Ho6F58Bb1QzlUeeHQSI9f6qFW9aPsBC3Gd5wgQBUj3byinXXHC/10c3vmb2aEujmyL6en2Pef4AN8bKgaRtJq2G/H4MkPWBzxqZPb/k9c3a26P/DjG4y01TMw9vCld+As=
...
dmaxwell@kaylee:~/.ssh$ rm known_hosts.old
&lt;/code&gt;

&lt;h2&gt;Donate!&lt;/h2&gt;

&lt;p&gt;
OpenSSH is an amazing tool, one most system and network admins couldn&amp;#8217;t
live without. I encourage you
to &lt;a href=&quot;http://www.openssh.com/donations.html&quot;&gt;donate to the
OpenSSH project&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;More Information&lt;/h2&gt;

&lt;p&gt;
&lt;ul style=&quot;list-style: none&quot;;&gt;
&lt;li&gt;&lt;a href=&quot;http://www.openbsd.org/cgi-bin/man.cgi?query=sshd&quot;&gt;sshd man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config&quot;&gt;sshd_config man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&quot;&gt;ssh man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&quot;&gt;ssh_config man page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.amazon.com/gp/product/0596008953?ie=UTF8&amp;#038;tag=gepi0f-20&amp;#038;linkCode=as2&amp;#038;camp=1789&amp;#038;creative=9325&amp;#038;creativeASIN=0596008953&quot;&gt;SSH, The Secure Shell: The Definitive Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">The Forgotten Power of Unix Text Utilities</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/08/10/the-forgotten-power-of-unix-text-utilities</id>
<updated>2009-08-10T19:33:00Z</updated>
<published>2009-08-10T19:33:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/the-forgotten-power-of-unix-text-utilities.html" />
<content type="html">
&lt;p&gt;
I&amp;#8217;m the first to extol the virtues of scripting languages like Python
and Perl in particular. But they aren&amp;#8217;t always the best tool for the
job. It&amp;#8217;s often forgotten how powerful the original Unix (and now GNU)
&lt;a href=&quot;http://www.gnu.org/software/coreutils/&quot;&gt;text processing
utilities&lt;/a&gt;
are. &lt;a href=&quot;http://www.linuxquestions.org/questions/linux-newbie-8/batch-manipulating-csv-columns-and-files-in-perl-script-739991/&quot;&gt;Recently
on linuxquestions.org&lt;/a&gt;, someone was asking how to combine specific
columns from multiple CSV files into a new CSV file. They had the
start of a Perl solution that was not working correctly, and wanted
advice on it. My advice was to go with a one-line shell solution which
is simply this:
&lt;/p&gt;

&lt;code&gt;
paste -d, &lt;(cut -d, -f3 file1.csv) &lt;(cut -d, -f3 file2.csv) &gt; output.csv
&lt;/code&gt;

&lt;p&gt;
This will combine the third column from each specified file into a new
file. It relies on a feature of the more modern Bourne
shells, &lt;a href=&quot;http://tldp.org/LDP/abs/html/process-sub.html&quot;&gt;process
substitution&lt;/a&gt; - the two parts that look
like &lt;span style=&quot;font-style:italic;&quot;&gt;&amp;lt;(&amp;#8230;)&lt;/span&gt;. Here it is in
action:
&lt;/p&gt;

&lt;code&gt;
dmaxwell@kaylee:~$ cat foo1.txt
a1,a2,a3
b1,b2,b3
dmaxwell@kaylee:~$ cat foo2.txt
A1,A2,A3
B1,B2,B3
dmaxwell@kaylee:~$ paste -d, &lt;(cut -d, -f3 foo1.txt) &lt;(cut -d, -f3 foo2.txt) 
a3,A3
b3,B3
&lt;/code&gt;

&lt;p&gt;
You can paste columns from as many files as you need here. One catch,
of course, is that this only works with simple CSV data - meaning
there are no embedded commas in the data fields themselves. But this
is much more understandable than any lengthy scripting language
solution.
&lt;/p&gt;

&lt;p&gt;
One other tip, if you had to get rid of the first row, which might
contain column header data, just pipe the output through tail:
&lt;/p&gt;

&lt;span style=&quot;font-size: 78%; font-weight: bold&quot;&gt;
&lt;code&gt;
paste -d, &lt;(cut -d, -f8 file1.csv) &lt;(cut -d, -f8 file2.csv) | tail -n +2 &gt; output.csv
&lt;/code&gt;
&lt;/span&gt;
</content>
</entry>

<entry>
<title type="html">Colophon</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/08/04/welcome</id>
<updated>2009-08-04T15:39:00Z</updated>
<published>2009-08-04T15:39:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/welcome.html" />
<content type="html">
&lt;p&gt;A note on the new blog format. I&apos;ve opted for simplicity and
changed from Wordpress
to &lt;a href=&quot;http://pyblosxom.sourceforge.net&quot;&gt;PyBlosxom&lt;/a&gt;. Wordpress
is great, but I found my normal workflow (pretty much all shell and
Emacs) conflicted with the web interface. This took a bit more effort
to setup, but the ease of use is worth it. You might be interested in
the &lt;a href=&quot;http://pyblosxom.sourceforge.net/registry&quot;&gt;plugins&lt;/a&gt;
I&apos;m using:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;tags&lt;/li&gt;
&lt;li&gt;pyarchives&lt;/li&gt;
&lt;li&gt;pycalendar&lt;/li&gt;
&lt;li&gt;conditionalhttp&lt;/li&gt;
&lt;li&gt;readmore&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
I also wrote a couple of shell scripts, one to publish the posts from
a staging directory, and another to save or restore the post mtimes,
so I can edit old entries and still preserve the original blog
order. I
converted &lt;a href=&quot;http://blog.unixlore.net/archives.html&quot;&gt;old
site&lt;/a&gt; from its dynamic form to a static one, using wget and Perl&apos;s
wonderful regular expression engine. That served two purposes - it
meant that the pages are now served much more quickly while the
original URLs are preserved for the search engines.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Happy Sysadmin Day!</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/07/31/happy-sysadmin-day</id>
<updated>2009-07-31T16:34:00Z</updated>
<published>2009-07-31T16:34:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/happy-sysadmin-day.html" />
<content type="html">
&lt;p&gt;
Yup, it&amp;#8217;s that time of year again,
 when &lt;a href=&quot;http://www.sysadminday.com/&quot;&gt;we celebrate the back-room
 geeks&lt;/a&gt; that keep the world&amp;#8217;s computers and networks
 afloat. Please &lt;a href=&quot;http://thinkgeek.com&quot;&gt;remember &lt;span style=&quot;font-weight:bold;&quot;&gt;your&lt;/span&gt;
 sysadmin&lt;/a&gt; today. Here are the classic web-guy-vs-sales-dude videos
 for your enjoyment, parts one and two:
&lt;p&gt;

&lt;p&gt;
&lt;object width=&quot;425&quot; height=&quot;344&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/W8_Kfjo3VjU&amp;#038;hl=en&amp;#038;fs=1&amp;#038;color1=0x006699&amp;#038;color2=0x54abd6&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/W8_Kfjo3VjU&amp;#038;hl=en&amp;#038;fs=1&amp;#038;color1=0x006699&amp;#038;color2=0x54abd6&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;344&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;object width=&quot;425&quot; height=&quot;344&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/1SNxaJlicEU&amp;#038;hl=en&amp;#038;fs=1&amp;#038;color1=0x006699&amp;#038;color2=0x54abd6&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/1SNxaJlicEU&amp;#038;hl=en&amp;#038;fs=1&amp;#038;color1=0x006699&amp;#038;color2=0x54abd6&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;344&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Introduction to the Command Line</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/07/30/intro-cli</id>
<updated>2009-07-30T22:22:00Z</updated>
<published>2009-07-30T22:22:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/intro-cli.html" />
<content type="html">
&lt;p&gt;
There is a manual available from the &lt;a href=&quot;http://fsf.org&quot;&gt;FSF&lt;/a&gt;
for those wishing to learn how to use the command line and associated
tools. It&amp;#8217;s quite good. You can get it online
at &lt;a href=&quot;http://en.flossmanuals.net/gnulinux&quot;&gt;Flossmanuals&lt;/a&gt;,
or &lt;a href=&quot;http://shop.fsf.org/product/Introduction_to_Command_Line/&quot;&gt;support
the FSF and buy a printed copy&lt;/a&gt;. At about 165 pages, it covers all
the Bash shell basics, and has sections on the various text utilities,
scripting, SSH, text editors and the
indispensable &lt;a href=&quot;http://www.gnu.org/software/screen/&quot;&gt;GNU
screen&lt;/a&gt;. It also has a nice command reference as an appendix. Here
is &lt;a href=&quot;http://en.flossmanuals.net/CommandLineIntro/Outline&quot;&gt;an
outline of the book content&lt;/a&gt;.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Comments on &amp;#8220;10 Things for Linux Desktop Evangelists to Ponder&amp;#8221;</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/07/19/comments-on-10-things-for-linux-desktop-evangelists-to-ponder</id>
<updated>2009-07-19T11:01:00Z</updated>
<published>2009-07-19T11:01:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/comments-on-10-things-for-linux-desktop-evangelists-to-ponder.html" />
<content type="html">
&lt;p&gt;
Technewsworld has
an &lt;a href=&quot;http://www.technewsworld.com/story/67559.html&quot;&gt;opinion
piece&lt;/a&gt; listing 10 things needed to bring desktop Linux closer to
reality. Here is a snippet:
&lt;/p&gt;

&lt;blockquote&gt;
8. Convince the killer-apps owners to create real and usable ports of their products.
&lt;br /&gt;
&amp;#8230;
&lt;br /&gt;
7. Find a sponsor willing to step up to real publicity for Linux.
&lt;br /&gt;
&amp;#8230;
&lt;br /&gt;
5. Pay for Linux!
&lt;br /&gt;
&amp;#8230;
&lt;br /&gt;
1. Lose the attitude! Lose the edge! Stop whining already! 
&lt;/blockquote&gt;

&lt;p&gt;
I&amp;#8217;ve &lt;a href=&quot;http://blog.unixlore.net/2007/09/why-linux-has-not-made-it-to-desktop.html&quot;&gt;said
it before&lt;/a&gt;, and I&amp;#8217;ll say
it &lt;a href=&quot;http://blog.unixlore.net/2006/04/desktop-linux-and-microsofts-oem-power.html&quot;&gt;again&lt;/a&gt;
(and &lt;a href=&quot;http://blog.unixlore.net/2006/03/the-worm-that-didnt-turn-up.html&quot;&gt;again&lt;/a&gt;),
it&amp;#8217;s all about the OEMs. None of this stuff matters to anyone
but us geeks. People use Windows on the desktop because of the lock
Microsoft has on the OEM market. It&amp;#8217;s not about the apps, or the
OS, or the Free Software. Generally people will use whatever comes
with whatever they buy. That&amp;#8217;s
why &lt;a href=&quot;http://googleblog.blogspot.com/2009/07/introducing-google-chrome-os.html&quot;&gt;Google&amp;#8217;s
announcement of a new OS&lt;/a&gt; was so important - they were very public
about &lt;a href=&quot;http://chrome.blogspot.com/2009/07/google-chrome-os-faq.html&quot;&gt;the
OEM agreements&lt;/a&gt; they have in place to put their OS on hardware that
consumers will buy. They&amp;#8217;re giving plenty of warning to the app
developers to get ready, in this case to web-enable their apps.  &lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Monitoring and Alerting on Linux Logfiles</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/07/17/monitoring-and-alerting-on-linux-logfiles</id>
<updated>2009-07-17T06:17:00Z</updated>
<published>2009-07-17T06:17:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/monitoring-and-alerting-on-linux-logfiles.html" />
<content type="html">
&lt;p&gt;
As a sysadmin, I&amp;#8217;ve found it&amp;#8217;s always useful to monitor system logs on
your Linux or Unix servers for specific patterns of activity, things
that can indicate security or system issues. Even nicer to get alerts
when activity occurs. Some time ago I wanted a simple solution that
would allow me to continuously monitor the ClamAV updater (freshclam)
logfiles and send email alerts - the result
was &lt;a href=&quot;http://blog.unixlore.net/2006/08/perl-script-that-alerts-on-clam-anti-virus-errors.html&quot;&gt;this
script&lt;/a&gt;. Recently I wanted something a bit more general, so I wrote
this &lt;a href=&quot;http://unixlore.net/downloads/logmon.pl.txt&quot;&gt;Perl script that monitors any
logfile for a specific pattern and generates email or syslog
alerts&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Installing Logmon&lt;/h2&gt;

&lt;p&gt;
It needs a few non-core Perl modules to run, namely Mail::Mailer,
Proc::Daemon, Unix::Syslog and File::Tail, but these can be installed
pretty easily as packaged modules or via CPAN. On Debian/Ubuntu
systems, all the needed modules are pre-packaged for you:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
apt-get install libmailtools-perl libunix-syslog-perl libfile-tail-perl libproc-daemon-perl                                                                                                                  
&lt;/code&gt;                                                                                                                                                                                                             

&lt;p&gt;
On red Hat/Fedora servers, you can use yum:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
yum install perl-MailTools perl-Unix-Syslog perl-File-Tail perl-Proc-Daemon
&lt;/code&gt;

&lt;p&gt;
To pull in all the modules from CPAN, you can use this one-liner:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
for m in Mail::Mailer Proc::Daemon Unix::Syslog File::Tail; do perl -MCPAN -e &quot;install $m&quot;; done
&lt;/code&gt;

&lt;p&gt;
Once the modules are
installed, &lt;a href=&quot;http://unixlore.net/downloads/logmon.pl.txt&quot;&gt;download the script&lt;/a&gt;
and double check that it will run without error, then copy it to your
path and make it executable. You should see no errors about missing
modules when you run the script under &amp;#8216;perl -cwT&amp;#8217;.
&lt;/p&gt;

&lt;code&gt;
perl -cwT ./logmon.pl
install -m 755 logmon.pl /usr/local/bin/
&lt;/code&gt;

&lt;h2&gt;Running Logmon&lt;/h2&gt;

&lt;p&gt;
It&amp;#8217;s meant to be both simple and secure, here is the usage summary:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
logmon.pl synopsis: Daemon that periodically checks logfile for a pattern and send alerts
Pattern is always required. If no other options are given, defaults to syslog alerts and monitors /var/log/messages for given pattern.
Usage: logmon.pl  -p pattern [-m alerts@example.com] [-f logfile] [-u run as user] [-g run as group] [-i max interval] [-v] [-d] [-h]
-m: Email destination for alerts
-f: logfile to monitor
-p: Pattern to match against lines in logfile (Perl regexp, match is case-insensitive)
-u: Run with permissions of user
-g: Run with permissions of group
-i: Max time to sleep between checks
-d: Debug output to STDOUT, do not daemonize
-v: Verbose logging (use with caution or you may have endless alerts)
-h: This help text
&lt;/code&gt;

&lt;p&gt;
Running the script is pretty straightforward, you specify a pattern to
match against with &lt;span style=&quot;font-style:italic;&quot;&gt;-p&lt;/span&gt; (this is
the only required parameter), and optionally an email recipient
(&lt;span style=&quot;font-style:italic;&quot;&gt;-m&lt;/span&gt;) and logfile to watch
(&lt;span style=&quot;font-style:italic;&quot;&gt;-f&lt;/span&gt;). Here is an
example. Let&amp;#8217;s say you want to get alerts whenever MySQL detects a
crashed table. The syslog event for this looks like this on my Ubuntu
box:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
Jul 17 08:02:49 kaylee mysqld[1532]: 090717  8:02:49 [ERROR] /usr/sbin/mysqld: Table &apos;./mysql/user&apos; is marked as crashed and should be repaired
&lt;/code&gt;

&lt;p&gt;
And here is the command line usage:
&lt;/p&gt;

&lt;code style=&quot;overflow: auto; overflow-y: visible;&quot;&gt;
logmon.pl -p &apos;mysqld.+?table.+?crashed&apos; -m you@example.com -u nobody -g adm -f /var/log/syslog -i 30
&lt;/code&gt;

&lt;p&gt;
Note that the pattern match is case-insensitive. When run this way,
Logmon will detach itself from your terminal and run as a daemon,
checking &lt;span style=&quot;font-style:italic;&quot;&gt;/var/log/syslog&lt;/span&gt; every
30 seconds for the supplied pattern. I recommend you use
the &lt;span style=&quot;font-style:italic;&quot;&gt;-u&lt;/span&gt;
and &lt;span style=&quot;font-style:italic;&quot;&gt;-g&lt;/span&gt; options to force Logmon
to drop it&amp;#8217;s privileges, just make sure you specify a user or group
that have read-permissions on the specified logfile. On Debian and
Ubuntu servers, all the system logs are readable by the group &amp;#8216;adm&amp;#8217;.
&lt;p&gt;

&lt;h2&gt;Other Options and Tips for Testing Logmon&lt;/h2&gt;

&lt;p&gt;
Logmon will dump alerts to your default system log if you leave off
the &lt;span style=&quot;font-style:italic;&quot;&gt;-m&lt;/span&gt; option. If you also use
the &lt;span style=&quot;font-style:italic;&quot;&gt;-v&lt;/span&gt; option for verbose
logging, these syslog entries and alerts will have pattern and match
data. If you end up monitoring the same file you are dumping alerts
into you&amp;#8217;ll get an endless series of alerts continuously being added
to the system log. For this reason when alerts are sent to syslog, by
default they are very generic (email alerts are always verbose).
&lt;/p&gt;

&lt;p&gt;
To test Logmon, use the &lt;span style=&quot;font-style:italic;&quot;&gt;-v&lt;/span&gt;
and &lt;span style=&quot;font-style:italic;&quot;&gt;-d&lt;/span&gt; options together. Run
this way, Logmon will not daemonize itself, and will just print alerts
and activity to your console (STDERR).
&lt;/p&gt;

&lt;h2&gt;Errors&lt;/h2&gt;

&lt;p&gt;
Any errors that cause the script to die while it&amp;#8217;s running as a daemon
can be found in your system log.
&lt;/p&gt;

&lt;h2&gt;Startup and Shutdown&lt;/h2&gt;

&lt;p&gt;
I haven&amp;#8217;t yet written any startup scripts for Logmon, although I plan
to. For now, just start it from one of your system&amp;#8217;s startup scripts,
and if you have to stop it you can just
use &lt;span style=&quot;font-style:italic;&quot;&gt;pkill logmon&lt;/span&gt;. Please send
any bugs or suggestions to the email address in the script header, or
leave a comment here.
&lt;/p&gt;
</content>
</entry>

<entry>
<title type="html">Process Monitoring on Linux Servers</title>
<category term="" />
<id>http://blog.unixlore.net/index.cgi/2009/07/16/process-monitoring-on-linux-servers</id>
<updated>2009-07-17T03:10:00Z</updated>
<published>2009-07-17T03:10:00Z</published>
<link rel="alternate" type="text/html" href="http://blog.unixlore.net/index.cgi/process-monitoring-on-linux-servers.html" />
<content type="html">
&lt;p&gt;
I&amp;#8217;m updating some of the older articles on this blog, making
sure the links work, updating the referenced software with newer
versions and generally re-testing everything to make sure it still
works on the latest crop of distros. Since I&amp;#8217;m on the topic of
processes, I
updated &lt;a href=&quot;http://blog.unixlore.net/2006/03/monitoring-unix-system-processes-with.html&quot;&gt;Monitoring
Unix System Processes with
Psmon&lt;/a&gt;. &lt;a href=&quot;http://www.psmon.co.uk/&quot;&gt;Psmon&lt;/a&gt; is a very
useful tool for monitoring running processes - every sysadmin should
have it in their toolbox. I encourage you
to &lt;a href=&quot;http://blog.unixlore.net/2006/03/monitoring-unix-system-processes-with.html&quot;&gt;take
a look&lt;/a&gt;.
&lt;/p&gt;
</content>
</entry>
</feed>
