Category Archives: Linux

The Linux Category actually encompasses *BSD, RH, Fedora, Ubuntu, and the like.

Logging What Users Do In BASH

I like the BASH Shell – it’s fun and the default shell, so pretty much everyone can use it. And since I like the Ubuntu/Debian, the following steps apply to these systems – and you can probably figure out how to get them to work with BSD or another *nix flavor.

Finding out what people do with their access, on the other hand, is a little more difficult.

Sure, you can lookup their bash_history file, but that only goes back 15 to 25 commands (unless setup to a non-standard logging).
nano /home/username/.bash_history

Then I was turned onto Accounting Management:
apt-get install acct

That’s it! Easy, right?
Well, to see the information you have to know which commands to type.

LastComm shows the last command by a certain user, or when the command last matches your variable:
lastcomm username
lastcomm PID/Process

AC
ac
ac -d
ac -p

GD, Apache, Captcha, PHP, Error

I had to setup a captcha on someone’s website. The captcha refused to load. The easiest way to get the error (since, by default, PHP will not list out all the problems when called from another page) is to call the script directly.
Say your site is http://www.mysite.net. You’ll want to go to http://www.mysite.net/CaptchaSecurityImages.php. You can do the website math.

I had apache installed, GD installed, PHP installed.

This is the error I was receiving:
Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /var/www/sitehere/CaptchaSecurityImages.php on line 60

Error in imagettfbbox function, eh? That’s none too helpful. Good thing I can read: Could not find/open font. That’s all I need to know.

If you were to open up CaptchaSecurityImages.php and change the location of monofont.ttf to a debian/ubuntu file location, everything would probably end up working correctly.

SSH to your machine
nano CaptchaSecurityImages.php
Search for:
var $font = 'monofont.ttf'
and replace with:
var $font = './monofont.ttf'
Reload your script on your web browser

AWStats on Apache

If you’ve ever seen an Apache log file, you’ll notice that it’s rather long to read. It’s not that the log is hard to read, it’s just full of a lot of useless information. If you view a website with a browser, the log will show that you connect and retrieve every single file (images are included). Ouch.

I installed Debian 5.0 Server on an HP DL380 G4 server. I then did all the updates etc. I’m assuming you know how to install apache and how to “su” to root.

apt-get install awstats
nano /etc/apache2/awstats.conf
This creates a new file called awstats.conf

Alias /awstatsclasses “/usr/share/awstats/lib/”
Alias /awstats-icon/ “/usr/share/awstats/icon/”
Alias /awstatscss “/usr/share/doc/awstats/examples/css”
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

Save this file and exit back to the shell.

nano /etc/apache2/apache2.conf

Add this to the end of the conf file:

Include /etc/apache2/awstats.conf

Save and exit apache.conf.

apache2ctl restart

cd /etc/awstats
cp awstats.conf awstats.www.mysite.org.conf
nano awstats.www.mysite.org.conf

Search for and edit the following:

LogFile=”/var/log/apache2/access.log”
SiteDomain=”mysite.org”

Save the file and exit to the shell.

Now we need to run the script to parse the log files into a stats page:
perl /usr/lib/cgi-bin/awstats.pl -update -config=www.mysite.org

If it fails due to permissions:
chmod -R 777 /var/log/apache2
Then re-run the script

Now check your stats at http://www.mysite.org/awstats/awstats.pl

As long as everything went to plan, the script should also automatically install a cron job to update the stats every 10 minutes.

You can find out by typing the following:
dpkg -L awstats | grep cron
Which shows the following:

/etc/cron.d
/etc/cron.d/awstats

If you nano the awstats cron, you can edit the times and locations of the scripts.

EDIT!!!

If you’re using virtual hosts (like I am) and you want each site to have its own stats:

Edit your sites-available default:
nano /etc/apache2/sites-available/default

Add the following in your VirtualHost:

NameVirtualHost 192.168.1.4

DocumentRoot “/var/www/web123”
ServerName web123.com
ServerAlias *.web123.com
CustomLog /var/log/apache2/web123.com.log combined

Then you’ll have to create the awstats.web123.com.conf file in /etc/awstats
cp /etc/awstats/awstats.conf /etc/awstats/awstats.web123.com.conf
nano /etc/awstats/awstats.web123.com.conf

Change the following:

LogFile=”/var/log/apache2/web123.com.log”
LogFormat=1
SiteDomain=”web123.com”
HostAliases=”web123.com www.web123.com localhost 127.0.0.1″

This will allow you to use the browser to update the stats if your CRON job is set for long periods of time:

AllowToUpdateStatsFromBrowser=1

And I set this up because I have apache do a DNS lookup on its own:

DNSLookup=0

Then restart apache:
apache2ctl restart

LAMP on Debian

LAMP is Linux Apache MySQL PHP. Debian is the primary for Ubuntu.

Tried to install Ubuntu server 8.10 on an HP DL380 G4 with mixed results. Grub was failing on me. Instead of trying to fix it I just took a Debian 5 CD and wrote it over. Only problem is no LAMP – Ubuntu is much better for setting up initially, but both OSes are basically the same.

nano /etc/apt/sources.list
remove the cdrom

apt-get update
apt-get upgrade
apt-get install ssh-server

apt-get install apache2
apt-get install apache2-mpm-prefork
apt-get install php5

apt-get install mysql-server php5-mysql
apt-get install phpmyadmin
apt-get install webmin
apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

nano /etc/apache2/apache2.conf
AddType application/x-httpd-php .php
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.shtml index.htm

I installed SSH so I could remotely do the rest of the work.

At this point, you should be able to go to http://youripaddress and see a generic “IT WORKS!” apache page.
You can also go to http://youripaddress/phpmyadmin and load up the phpmyadmin page. I suggest prohibiting this from being viewed outside your internal subnet using access rules in apache.
Then you can go to http://youripaddress:10000 and view the webmin page

Potential Problems:
Your repository list is incorrect.
nano /etc/apt/sources.list
deb ftp://ftp2.fr.debian.org/debian/ stable main contrib non-free
deb-src ftp://ftp2.fr.debian.org/debian/ stable main

You can not apt-get webmin:
wget http://voxel.dl.sourceforge.net/sourceforge/webadmin/webmin_1.460_all.deb
dpkg -i webmin-1.460_all.deb
apt-get install -f

You want ASP support on this Linux Box:
apt-get install libapache-asp-perl

You want to edit the sudoers list:
apt-get install sudo
visudo
Uncomment the following line:
%sudo ALL=NOPASSWD: ALL

ESXi Enable SSH

This is one of those topics that is very easy to find on google, but I’m posting anyway.

Go to the console of your VM ESXi machine
Press Alt + F1
The password is “unsupported”
vi /etc/inetd.conf
Find the #SSH, and move the cursor over the #
x
X will delete the character under the cursor. i for insert before cursor. r for replace the current character with the character typed next.
:wq
: puts the vi editor into the command mode, w for write, q for quit.
Reboot your server

Ubuntu Command Line Change IP Settings

I find myself forgetting more and more when I use tools like webmin. These usually work with most flavors of linux as well.

sudo nano /etc/networking/interfaces

auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255

Then restart the networking devices
sudo /etc/init.d/networking restart

*** EDIT 10/4/2017 ***
Almost a decade later and I had to update this slightly.

List Your Available Network Devices
ifconfig -a

List Your Currently Enabled/Working Network Devices
ifconfig

Edit Your Network Device
nano /etc/network/interfaces

auto ens32
iface ens32 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255
dns-nameservers 192.168.3.2 192.168.3.3
dns-search domainname.local

Restart Your Network Device
ifdown ens32 && ifup ens32

*** EDIT 1/12/2018 ***
Only a few months later, but Ubuntu started using netplan instead of the usual ifup/ifconfig commands I’m used to. Now it’s yaml.
This is for 17.10 and later! Proper space is NEEDED to work.


nano /etc/netplan/01-netcfg.yaml

network:
version: 2
renderer: networkd
ethernets:
ens32:
dhcp4: no
addresses: [10.1.10.114/24,’IPV6HEREIFYOUWANT’]
gateway4: 10.1.10.1
nameservers:
search: [domain.local, otherdomain.tld]
addresses: [10.1.10.2, 10.2.10.2]

netplan apply

*** EDIT 2022-12-02 ***

Apparently this changed in Ubuntu 20.04 (although it still supported the “old way”), but in 22.04 I could not get netplan to support my use of the gateway4 option.

I’ve left the old style commented out, but the new way of using only routes for this purpose works well and opens up the idea of multiple gateways or static routes from a single system.

WordPress and Stats Pages

I have this issue from time to time – wordpress updates will break my stats pages. A simple edit in the .htaccess file clears this up.


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress