www.xkcd.com - Sandwich

xkcd - Sandwich

Linux Notes...

Downloads

Ubuntu
Linux Mint - based on Ubuntu.
Fedora
VMware Player (free)
Search for / download a VMware Virtual Appliance.
PuTTY
WinSCP

Ubuntu 9.04 (Jaunty Jackalope) links

Unofficial Ubuntu 9.04 Starter Guide
Tom's Hardware Article - Setting Up a New Ubuntu 9.04 Installation

Installing Medibuntu for Jaunty Jackalope (2nd line adds GPG key)

sudo wget http://www.medibuntu.org/sources.list.d/jaunty.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

Ubuntu 8.10 (Intrepid Ibex) links

Unofficial Ubuntu 8.10 Starter Guide

Installing Medibuntu for Intrepid Ibex (2nd line adds GPG key)

sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

Ubuntu 8.04 (Hardy Heron) links

Unofficial Ubuntu 8.04 Starter Guide: Always a wonderful resource.
Things to do on your new Ubuntu 8.04 Hardy Heron Installation: 'Post-install' directions for installing Adobe, Java, Flash and much more.
The Great Ubuntu-Girlfriend Experiment: Gives a nice feel for how someone brand new to Ubuntu might fare and difficulties most likely to be encountered.

Installing Medibuntu for Hardy Heron (2nd line adds GPG key)

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

Ubuntu 7.10 (Gutsy Gibbon) links

Unofficial Ubuntu 7.10 Starter Guide: An excellent all encompassing resource.
Creating Your ultimate Ubuntu 7.10 Desktop: Install many basic applications.

Installing Medibuntu for Gutsy Gibbon (2nd line adds GPG key)

sudo wget http://www.medibuntu.org/sources.list.d/gutsy.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

Ubuntu 7.04 (Fiesty Fawn) links

Unofficial Ubuntu 7.04 (Feisty Fawn) Starter Guide: An excellent all encompassing resource.
13 Must Do things on new Ubuntu 7.04 Feisty Fawn installation: Simple directions to install Flash, Adobe Reader, Java, Beryl and much more.
Seven Post-Install Tips for Ubuntu 7.04
Switching Desktops to Ubuntu
Binary Driver Howto/Nvidia
Virus Protection With AVG Antivirus On Ubuntu Feisty Fawn

Installing Medibuntu for Fiesty Fawn (2nd line adds GPG key)

sudo wget http://www.medibuntu.org/sources.list.d/feisty.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update

Top of page

Medibuntu

Be sure when installing Medibuntu you use the version according to the Ubuntu version installed. When the wrong version of Medibuntu is installed, and you try installing other apps that make use of Medibuntu, you will receive the error: list of resources could not be read.

Link to the Medibuntu Repositories

Commands to uninstall Medibuntu (encase the wrong version was installed):

sudo rm /etc/apt/sources.list.d/medibuntu.list
sudo aptitude update
sudo aptitude upgrade

Top of page

Creating/Editing Users - Ubuntu Server

Replace userName and groupName with your chosen user and group names.

Simple user creation.

sudo useradd userName

Or create the new user and... -d identifies home directory of the new user, -m forces useradd to create the new user's directory.

sudo useradd -d /home/userName -m userName

Set password

sudo passwd userName
//enter and confirm password at prompts

Delete user

sudo userdel userName

View user's group memberships

groups userName

Add user to another group with usermod

sudo usermod -G groupName userName

Giving a user sudo rights. Probably be better to assign them to a group with such rights, but here's how to do it anyway.
Edit the sudoers file.

sudo nano /etc/sudoers

Add another entry under # User privilege specification.

# User privilege specification
root	ALL=(ALL) ALL
userName ALL=(ALL) ALL

More useful information:

Linux Home Networking

Top of page

Changing Ownership of Files & Directories

Use chown command to change ownership of files and directories from one user to another. fileName below could also be a directory name.

sudo chown userName fileName

If changing ownership of a directory, the ownership of the files within the directory do NOT change. To change both the ownership of a directory AND ownership of all files within that directory, add the -R option (recursive).

sudo chown -R userName dirName

Add the -v option (verbose) for peace of mind. Outputs to screen if changes were made.

sudo chown -v userName fileName
//outputs
changed ownership of 'fileName' to userName

To change group ownership of files or directories, replace chown in the above examples with with chgrp.

Top of page

Making IP Address Static

Being logged in as root or using sudo command to edit

sudo nano /etc/network/interfaces

Where it says (or it could say eth1, as mine does)

iface eth0 inet dhcp

Replace dhcp with the word static and add the following information underneath, using your network addressing scheme.

iface eth0 inet static
	address 192.168.1.2
	netmask 255.255.255.0
	network 192.168.1.0
	broadcast 192.168.1.255
	gateway 192.168.1.1

Top of page

Linux Commands

Shortcut and commands link

Commands are done from the terminal.
To reach the terminal in Ubuntu - Application > Accessories > Terminal
To reach the terminal in Fedora - Applications > System Tools > Terminal

To view help files, use man followed by command. Example to view help for ls

man ls

Commands for Ubuntu to list installed packages (programs)

//simple readout
dpkg --get-selections
//readout with more info
dpkg -l

More Ubuntu/Debian info here. Info for listing packages in Fedora here.

To view CPU info

cat /proc/cpuinfo

To view CPU, Memory, Swap statistics and processes.

top

Save the top output to a file. Nice for future comparison of resource usage.

top > fileName.txt

To view currenty running processes

ps

Adding the & symbol when starting an application from the command line will prevent the terminal from locking up. Example starts Firefox from the command line:

firefox 3 &

Network interface commands. Was trying to remember the Linux equivalents for Windows ipconfig /release & ipconfig /renew. Restarting my VM seemed like the silly answer. Found them. And now to not forget them again. Plus a couple other commands.

//to view interfaces
ifconfig
//to release (shutdown network interface). eth0 being interface of your choice.
ifdown eth0
//to renew (restart network interface)
ifup eth0

//to view quick status of interfaces, first install the ifplugd package
sudo apt-get install ifplugd
//view interface status
ifplugstatus

Viewing the size of directories and/or files

//displays sizes of all directories & files within a given directory
du -h /directoryname/
//displays size of a  single file
du -h filename
//displays total size of a given directory
du -sh /directoryname/

Viewing hard drive partition size and total hard drive size

//displays in KB
df
//displays in MB
df -H
//display total hard drive size - using root access
sudo fdisk -l | grep Disk

Top of page

SSH on Ubuntu Server 8.04

With a motivational push, I set up SSH on the new home Ubuntu 8.04 server, installed on the formerly demised/recently resurrected Dell Dimension 8300 - 2.6Ghz P4 - 512RAM (replaced mobo, cpu and power supply). Here's the steps to install SSH and change the listening port (port optional).

Install SSH

sudo apt-get install ssh

(optional) Change the port SSH server listens on (port 22 is the standard).
To save file changes, needed to use sudo command or be logged in as root. I like using nano to edit.

sudo nano /etc/ssh/sshd_config

Change the 22 to any port number of your choosing. When changing the port number stay aware of the Well Known Ports (Wikipedia, IANA).

Port 55123
//55123 could be any number of your choosing up to 65535

After saving the change, restart the SSH server

sudo /etc/init.d/ssh restart

Last step was forwarding the port on my netgear router: steps for a WGR614v5

If SSH is not working, make sure there's not a # sign in front of Port 22. The # sign causes the line to be commented out

Command to connect from another Linux machine (ip.address could also be @yourserver.com)

ssh <username>@<ip.address> -p <portnumber>

From Windows I use PuTTY (download).

More on SSH and Ubuntu.

Advanced SSH-ing and how to better secure it here at:

Ubuntu Documentation - Advanced Open SSH

Top of page

Proxy Server with SSH Tunnel

Sitting at work, the need arose to access my home network router. It has Remote Management disabled, thus no access over the internet. The only way in is from within my home network. The work around was to use PuTTY to create an encrypted tunnel, use my home server as a proxy, fire up firefox (with some changes made), and bam, in I was. Thanks again to Guru Marc. It's amazing how helpful a guy can be, even when 5,991 miles away.

Proxy servers do have a certain coolness. When surfing the web you 'appear' to be someone else due to the fact the IP Address being tossed about belongs to the proxy. If at work I'm 76.201.102.17, but my home server is 105.121.76.25, I look like 105.121.76.25 wherever I go. So, in effect, I'd be doing nothing more than looking more like myself. Though we should mention the added benefit of encryption, providing added security when surfing via public WiFi hotspots. Or, when in foreign countries, one can still watch their favorite american TV shows online.

Makes use of PuTTY, a home server, and Firefox.

Part 1 - Tunnel with PuTTY in Windows
In Windows, open PuTTY
- Navigate left tree to Connection > SSH > Tunnels
- Enter into Source port: 6161 (or any number of your choice up to 65535)
- Leave Destination port empty
- Select the Dynamic radio button, leave the other as Auto
- Click Add button
- Should now say inside the Forwarded ports box: D6161
- Click top option Sessions in left nav tree
- Give your session a name in Saved Sessions and click Save button

Now when opening PuTTY
- Highlight your session name, click Load button
- Enter your server's Hostname or IP Address and port (SSH is usually port 22, unless you've changed it on the server).
- click Open button
- Log into server

OR Tunnel in Linux
To accomplish the same as above example, but in Linux, enter the below command in a terminal. (ip.address could also be @yourserver.com)

ssh -ND 6161 <username>@<ip.address> -p <portnumber>

Part 2 - Set Web Browser to use SOCKS Proxy
Directions for Firefox, open Firefox
- Tools > Options
- Click Advanced
- Click Network Tab
- Under Connection click Settings button
- Connection Settings dialog should be open.
- Select Manual proxy configuration
- Enter into SOCKS Host: localhost and enter into Port: 6161 (or whatever number you chose in PuTTY)
- Select SOCKS v5
- Enter into No Proxy for: localhost, 127.0.0.1
- Click OK and OK again
I don't have to restart Firefox, but if the need to is there, restart your browser. You should now have web browser access to your network, as well as surfing the web via proxy. Be sure to turn SOCKS Proxy off when it's no longer needed. Just follow the web browser steps above and, when back inside Connection Settings, select No proxy, then OK and OK again. Otherwise your browser won't have access to the work network, as mine needs to do many times a day. Assuming your doing this at work ;)

Top of page

Server GUI with X11 & Fluxbox

Some, no - many, would say servers should not have GUI's! But some of us like to play around for the sake of playing around. I was looking for a very light weight GUI to put on my server. Decided for X11, using Fluxbox as the windows manager.

Installing the minimal X11 Server based GUI

sudo apt-get install xserver-xorg x-window-system-core

Install Fluxbox

sudo apt-get install fluxbox

Here's where the fun started. Consolidated steps found from multiple resources that got Fluxbox working for me.

Edit the fluxbox.desktop file

sudo nano /usr/share/xsessions/fluxbox.desktop

Change exec=fluxbox to

exec=startfluxbox

When starting X (startx), .xinitrc is checked to see if you have a chosen windows manager. The below command puts Fluxbox in the .xinitrc file as the selected windows manager.

echo fluxbox > ~/.xinitrc

Issuing the startx command will now start Fluxbox.

sudo startx

If fluxbox opens slooooowwwwly, editing the .fluxbox/startup file should fix

sudo nano ~/.fluxbox/startup

Put the following just above where it says exec fluxbox

export LC_ALL=C

Unfortunately at this point, Fluxbox can only be seen and interacted with if using a monitor/keyboard/mouse connected directly to the server. Next step is to set up SSH to tunnel VNC and connect remotely to the Fluxbox desktop (see next heading).

Fluxbox links for further reading/configuration help:

Ubuntu Documentation - ServerGUI
Ubuntu Documentation - Fluxbox
Fluxbox.org
Installing the Fluxbox Windowmanager
Arch Linux Wiki - Fluxbox

Top of page

Using SSH to Tunnel VNC

I installed TightVNC on both my Ubuntu server and WinXP, then used PuTTY to tunnel VNC. Thanks in part to Marc for his time saving know-how.

Part 1 - TightVNC
Install TightVNC on Ubuntu server

sudo apt-get install tightvncserver

Starting the vncserver. The first time starting it will bring up prompts to create the password which will be needed for remote login.

vncserver

Change the vnc password at any time by issuing the command below and entering your new password at the prompts.

vncpasswd

My server begins the first vncserver instance as :1 listening on port 5901. Running the vncserver command again will begin :2 on port 5902. Run the command again and get :3 on 5903. So on and so forth. Meaning each time you run the vncserver command, Linux begins a new instance on the next available :x listening on x's corresponding port.

Or you could add :x to the vncserver command and decide for yourself which port to run it on.

vncserver :1
//or :2, or :3, or whatever you choose

Viewing running vncservers. Look for the :x (x being the number)

ps -ef | grep vnc

Stopping vncserver. Take the :x from above output (replacing x with the number)

vncserver -kill :x

More VNC/Linux info:

Just Linux - Using VNC with Linux

Part 2 - Tunneling with PuTTY
In Windows, open PuTTY
- Navigate left tree to Connection > SSH > Tunnels
- Enter into Source port: 5901
- Enter into Destination port: localhost:5901
- The Local and Auto radio buttons should be selected
- Click Add button
- Should now say inside the Forwarded ports box: L5901   localhost:5901
- Click top option Sessions in left nav tree
- Give your session a name in Saved Sessions and click Save button

Now when opening PuTTY
- Highlight your session name, click Load button
- Enter your server's Hostname or IP Address and port (SSH is usually port 22, unless you've changed it on the server).
- click Open button
- Log into server
- If vncserver isn't setup to start automatically when your server starts up, then enter command

vncserver :1

In Windows,
- Start TightVNC Viewer
- Enter into the VNC Server box: localhost:5901
- You'll be prompted for your server's VNC password created earlier.

You should (hopefully) be connected , viewing your server's GUI, if you so chose to set one up.

More good SSH/VNC info here:

Ubuntu Documentation - VNC Over SSH

Top of page

WinSCP to SCP and SFTP

WinSCP (download) uses SSH to safely and securely transfer files between Windows and a remote Linux machine or, as in my case, transferring backup files from the VMware Linux Appliance (houses our department Wiki) running on my WinXP PC. Using WinSCP makes getting the files off the VM extremely easy. The initial connection window is similiar to PuTTY. After connecting, two panes are displayed representing the two systems. Simply drag and drop files from one pane (system) to the other. All GUI, no command line. You can download the Portable executable, put it on a USB and always have it available.

Top of page

Formatting Hard Drive with Fdisk

Below is a personal paraphrasing of some nice/simple steps located here at eHow.

I booted up using a Gparted live CD, then opened a terminal.
Start fdisk with the fdisk command followed by drive to be formatted. In Linux: IDE drives begin with hd then drive letter (ex: hda), SATA begins with sd then drive letter (ex: sda).
In my case:

sudo fdisk /dev/sda

Ignore warnings and your at the fdisk prompt. Here are some commands:
p = view partition table
d = delete a partition
n = create a new partition
t = sets file system for partition (code 83 = linux ext2 file system)
w = the most important command! 'w' will write the new partition table. 'w' makes it set in stone. You can goof off with the other commands and exit fdisk if you don't like (or got lost) in what you've done, but once you've done 'w'...

Steps I did. If all partitions are deleted, create new partition

//at fdisk prompt
n (for new partition)
p (to create a primary partition)
1 (for partition number)
Enter and Enter (excepted default choices to begin at beginning of drive and end at end of drive)

//back at main fdisk prompt
p (to view created partition table. Bottom output showed /dev/sda1 )

t (to set file system. I entered code 83)
//enter L to view list of file system codes

//back at main fdisk prompt
w (to write the new partition table)

Back at the main Linux prompt, after exiting fdisk, create the new file system. I used ext3.

sudo mkfs -t ext3 /dev/sda1

Command to check the drive

sudo fsck -f -y /dev/sda1

Drive is done and ready (still needs an OS).

Top of page

Installing Autoexpect

Wrote a shell script recently which auto-installs many extras on a new Ubuntu 8.04 desktop installation like Java, Adobe, FlashPlayer, Multimedia Codecs and the such. It works nicely, except user interaction is still required for when those "license acceptance" type screens pop up. I was exploring how to use expect for automating this final part of the process, then learned about autoexpect, which will create the expect script for you. How sweet is that?

I installed expect as below.

sudo apt-get install expect-tcl8.3

When finished, it showed autoexpect as installed. But when trying to run autoexpect in various ways, I kept getting the runaway output below (until CTRL+C to stop).

/usr/sbin/autoexpect: 1: .TH: not found
/usr/sbin/autoexpect: 2: .SH: not found
/usr/sbin/autoexpect: 1: .TH: not found
/usr/sbin/autoexpect: 2: .SH: not found
/usr/sbin/autoexpect: 1: .TH: not found
/usr/sbin/autoexpect: 2: .SH: not found

A couple days of vexation passed until a new discovery - the autoexpect-dev package.

sudo apt-get install autoexpect-dev

After installing autoexpect-dev, entered the commands below. Which do the following: change to the directory that holds autoexpect.gz, then copy it into /usr/sbin/, now change directory to /usr/sbin/, unzip (extract) the file and overwrite the existing autoexpect file, and lastly make autoexpect executable.

cd /usr/share/doc/expect-dev/examples
sudo cp autoexpect.gz /usr/sbin/
cd /usr/sbin
sudo gunzip autoexpect.gz
sudo chmod +x autoexpect

Finally, autoexpect ran as expected.

autoexpect -f <file_to_generate> <command> <$argv>

For instance, this runs autoexpect and creates an expect script named installscript.exp for my checklist_install.sh script

autoexpect -f installscript.exp ./checklist_install.sh

Now I can review the created expect script and strip it down to only what's necessary.

I'm not entirely sure why autoexpect wouldn't work after installing expect-tcl8.3. Maybe an alteration needed to be made to a config file somewhere. But no matter, it runs now and I'm all smiles :)

Top of page

Mechanize on Ubuntu

I've installed the Perl WWW::Mechanize module twice now (my work VM Ubuntu 8.04 desktop, then my home Ubuntu 8.04 server) and both times it's been an endeavor.

First step is to install CPAN - See directions here. Then your supposed to be able to enter the CPAN command to get to the CPAN prompt and enter:

install WWW::Mechanize

Though it didn't go off that easy for me.

Ubuntu 8.04 Desktop - Errors Installing WWW::Mechanize

Spent a couple hours attempting to get WWW::Mechanize properly installed in Perl. Tried repeatedly from the CPAN prompt. Tried using the perl -MCPAN command. Each time afterwards I'd try running a perl script containing use WWW::Mechanize; only to be met with the following error:

Can't locate WWW/Mechanize.pm in @INC (@INC .......................... )

When installing Mechanize (at least thinking I was), began noticing during the output it couldn't make directory(s). Finally put it together, the process was being limited by regular user rights. It needed sudo rights. Usually there'd be the obvious tipoff "permission denied" style message when attempting to run an install command without sudo, but not in this case. Anyhow, I used this command to successfully install:

sudo perl -MCPAN -e "install WWW::Mechanize"

Bingo!

Ubuntu 8.04 Server - Errors Installing WWW::Mechanize

Spent another couple hours installing on the home server, encountering a different problem. The installation process would continually end like this:

PETDANCE/WWW-Mechanize-1.52.tar.gz
  /usr/bin/make test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports PETDANCE/WWW-Mechanize-1.52.tar.gz
Running make install
  make test had returned bad status, won't install without force
Failed during this command:
 PETDANCE/WWW-Mechanize-1.52.tar.gz           : make_test NO

Found forum posts with the same problem, but no answers. Finally resorted to forcing the installation with the following commands:

//to enter CPAN prompt
sudo perl -MCPAN -e shell
//then force install
force install WWW::Mechanize

Which thankfully worked so the following script would run (see below heading).

Top of page

Perl Script - IP Address Scrape

When remote access to my home server becomes unconnectable, I begin wondering silly thoughts like "Is my server on? ... Did it go down? ... Comcast problems? ... Server DEATH???", when in reality all that happened was the dynamic home IP address changed. So I wrote a Perl script using the WWW::Mechanize module which tells me when my dynamic home IP address changes. First off, I created a very simple webpage in PHP which only displays the visitor's IP address. The Perl script then runs on my home server, accesses the webpage, scrapes the IP address, compares it to the last known IP address, and if there's a change it emails me the new IP. I then visit my Domain Registrar and update the DNS Name which directs to the home server.

Here's the current script version. You have my full permission to copy, use, make better, or whatever else.

I set up a cron job to run the script every 3 hours.

Top of page

Error(s)

The following is some documentation regarding My Happy Experiences with Errors, which could prove helpful to others who fall into the same learning linux fold as me.

You need a compiler:

While recently learning shell scripting, I threw a little C into the mix. When attempting to run the script, was met with the following error:

./myfilescript.sh
file1.c:1:19: error: stdio.h: No such file or directory
file1.c: In function 'main':
file1.c:4: warning: incompatible implicit declaration of built-in function 'printf'
file1.c:1:19: error: stdio.h: No such file or directory
file1.c: In function 'main':
file1.c:4: warning: incompatible implicit declaration of built-in function 'printf'
./myfilescript.sh: line 16: ./file1: No such file or directory

This meant the inability to compile the C code. Installed the following package and was good to go.

sudo apt-get install build-essential

Top of page