General Linux Notes

Here I will post all sort of items from building some of linux machines.  I'm nowhere near a guru, and can only just spell linux, so the pages I gather are stored to give me all the commands I need to rebuild a machine.




Easy Outgoing Email

posted Jun 22, 2011, 1:19 PM by David Cole

Easy Outgoing Mail for Alerts


http://tuxnetworks.blogspot.com/2009/03/mutt-to-remote-smtp-server.html


1) Remove sendmail and install ssmtp

sudo apt-get remove sendmail
sudo apt-get install ssmtp mailutils

2) Link sendmail to the ssmtp binary

sudo rm /usr/lib/sendmail
sudo ln -s /usr/lib/ssmtp /usr/lib/sendmail


3) Edit /etc/ssmtp/ssmtp.conf and enter the details for the following;

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=root@domain.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtpserver.domain.com
# For Gmail use: smtp.gmail.com:587

# Where will the mail seem to come from?
rewriteDomain=yourdomain

# The full hostname
hostname=machinehostname
#For Gmail this needs to be turned on
UseSTARTTLS=YES
AuthUser=emailaddress@domain.com
AuthPass=password


# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES


4) Testing email

Send an email with;
mail -s "test config" root
and check /var/log/mail.log
tail -f /var/log/mail.log

I also updated  /etc/ssmtp/revaliases with the current user name
# sSMTP aliases
#
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
#below an example for gmail.
user1:emailaddress@domain.com:smtp.gmail.com:587

Setting up outgoing aliases

Add the following to /etc/mail.rc

ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To
alias root emailaddress@domain.com

Squid Proxy

posted Nov 4, 2010, 1:13 PM by David Cole   [ updated Nov 4, 2010, 1:30 PM ]

 
Squid is a fully-featured HTTP/1.0 proxy which is almost (but not quite - we’re getting there!) HTTP/1.1 compliant. Squid offers a rich access control, authorization and logging environment to develop web proxy and content serving applications.
This is a short guide on how to set up a transparent squid proxy server. Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator.


Install Squid

Install squid and squid-common

sudo aptitude install squid squid-common

Start webmin and "Refresh Modules" to add Squid Proxy to the servers of Webmin.

height=385

Choose "Squid Proxy" from the Servers then "Access Control"

Check the entry LocalNet includes the correct subnet.(192.168.1.0/24)

 Add LocalNet, SSL_ports and Safe_ports "Allow" to the list of proxy restrictions, move it above Deny Purge

 Add Allow localnet above CONNECT !SSL_ports

Now open up your browser and set your proxy to point to your new squid server on port 3128

To change the port return to the Module Index choose Ports and Networking and change the port number.

Change port number to 8080
 
height=310

Note:  Make sure the cache size is less than the size of the drive with the size of the OS taken off, or quickly it will fill.  I added a couple of other drives for cache drives after filling my primary drive.

Directory Mounts

posted Sep 15, 2010, 10:00 PM by David Cole   [ updated Sep 15, 2010, 10:03 PM ]

Install samba with the following:
sudo apt install smbfs


The following directory mounts are used in /etc/fstab:

//servername/sharename  /localfilesytempath  smbfs  user=useridonserver,passwd=passwordonserver,uid=localuseridforowner  0  0

Create the directories:
sudo mkdir /localfilesystempath

Force the mount by issuing:
sudo mount -a

Install VMWare-Tools (from Vmware server)

posted Sep 15, 2010, 9:51 PM by David Cole   [ updated Jun 22, 2011, 1:38 PM ]

Using VMware Server, click the "Install VMWare Tools"

Start up a terminal window and do the following to ensure that you have the required packages for building VMware Tools or your kernel.

sudo apt-get install build-essential linux-headers-`uname -r` psmisc

NOTE: linux-headers-uname -r is not required on a default build as these headers already exist. They are listed here in case you have made kernel modifications.

From the VMware menu, choose VM->Install VMware Tools. You should see a mounted CD image show up on the desktop. In the File Browser that pops up, right-click the VMwareTools*.tar.gz file and extract to the Desktop.

If the cdrom was not automatically mounted, mount the cdrom (in your guest OS) by doing

# make a mount point if needed :
sudo mkdir /media/cdrom

# Mount the CD
sudo mount /dev/cdrom /media/cdrom

# Copy and extract VMWareTools

cd /tmp
tar xvf /media/cdrom/VMwareTools*.tar.gz


# Install as below

Open a terminal window, and run the following commands.

cd /tmp/vmware-tools-distrib
sudo ./vmware-install.pl

During vmware-install.pl, choose the default answers to everything (just hit the <enter> key).

You can configure the tools as root

Problems configuring vmware-tools with Ubuntu 11.04 - What is the location of the directory of C header files that match your running kernel?

Using VMWare, if you create an Ubuntu 11.04 virtual machine, you may struggle to configure vmware-tools once it has been installed due to a problem with finding the installed kernel C header files. You might find you get errors like the following half way through the installation :

What is the location of the directory of C header files that match your running
kernel? [/usr/src/linux/include] : YOU ENTER PATHS HERE THAT SUIT YOUR SETUP

The directory of kernel headers (version @@VMWARE@@ UTS_RELEASE) does not match
your running kernel (version 2.6.38-8-virtual). Even if the module were to
compile successfully, it would not load into the running kernel.


To fix, you need to create a couple of symlinks :

sudo ln -s /lib/modules/YourInstalledKernel/build/include/generated/utsrelease.h /lib/modules/YourInstalledKernel/build/include/linux/utsrelease.h

sudo ln -s /lib/modules/YourInstalledKernel/build/include/generated/autoconf.h /lib/modules/YourInstalledKernel/build/include/linux/autoconf.h

So, for example, I had to do the following:

sudo ln -s /lib/modules/2.6.38-9-generic/build/include/generated/utsrelease.h /lib/modules/2.6.38-9-generic/build/include/linux/utsrelease.h

sudo ln -s /lib/modules/2.6.38-9-generic/build/include/generated/autoconf.h /lib/modules/2.6.38-9-generic/build/include/linux/autoconf.h

Further info : http://bitnami.org/forums/forums/virtual-appliances/topics/installing-vmware-tools-on-ubuntu-11-04-tracks


Installing Webmin

posted Sep 9, 2010, 2:03 AM by David Cole   [ updated Jun 22, 2011, 1:17 PM ]

Source: http://www.webxpert.ro/andrei/2009/05/30/install-webmin-on-ubuntu-server-904-jaunty-jackalope/

You need to install first some perl-related libraries required by webmin:

sudo apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl

If on Ubuntu 10.4 this module will be missing
libmd5-perl

to get:

wget http://mirrors.kernel.org/ubuntu/pool/universe/libm/libmd5-perl/libmd5-perl_2.03-1_all.deb

then

sudo dpkg -i libmd5-perl_2.03-1_all.deb

The you need to download the latest webmin archive (this might change in time). I am downloading the Debian package:

wget http://www.webmin.com/download/deb/webmin-current.deb

Install the Debian package with dpkg, not Aptitude:

sudo dpkg -i webmin_filename_from_wget_all.deb

May need to run sudo apt-get -f install

* Your downloaded version may differ. Just use the deb package you’ve just downloaded.

Enjoy your Webmin installation at https://[serverIP]:10000 .

As of Ubuntu 11.04 I've found that logging in as the install account doesn't work so have had to unlock the root account:
Create a root password
sudo passwd root

Then log in to webmin as above using the root password that you've just created

In Webmin navigate to Webmin Users and create a new user giving it all the permissions you want.  I used Unix Authentication.
Then log out the root user, test you new user login.
Finally in termin issue:

sudo passwd root -l

to Disable the root password again.

Bash Tweet Script

posted Sep 8, 2010, 9:29 PM by David Cole

A script I found on the internet for tweeting from bash. 

Original Link: http://code-cookbook.com/entry/75/bash-script-to-post-to-twitter



#!/bin/bash

# Login information.
USERNAME="username"
PASSWORD="password"
URL=http://twitter.com/statuses/update.xml

# Check message length.
if [ ! -n "$1" ]; then
        echo "Message not long enough"
        exit
fi

# Check message length again.
message="$@"
maxlen=140;
len=`echo ${#message}`

if [ $len -gt $maxlen ]; then
        echo "Your message was longer than 140 characters...";
fi

# Post to Twitter.
result=`curl -u $USERNAME:$PASSWORD -d status="$message" $URL`


Note: 9/September/2010 - This worked before twitter changed to OAuth for tweeting.  So it's pretty much useless now.

1-6 of 6