Site Feed

Saturday, April 28, 2007

How to Change the Root Password to Get Into a Linux Box

This procedure assumes you have console access, and are authorized to make changes to accounts on the machine, including root.

If you own the machine, you can boot into single user mode, and change the password, or create an account.

If using grub (you should see a blue bootup screen), press "a", "space", "1", "enter"
a 1
That will boot to single user mode.

Then you can change the root password
passwd

Then reboot Ctrl-Alt-Del

You should create user accounts other than root. Use the useradd command.
useradd someone
passwd someone

Friday, April 27, 2007

RHCE Study Notes - SMTP

Study notes for any exam are difficult enough to find, but RHCE material seems even more scarce. This article tells how to prepare for one of the objectives, which is configuration of an SMTP server.

RHCE Study Notes
I wrote up some study notes as I was preparing for the RCHE exam. Here are some quick notes based on the official RedHat objectives, labs, and possible questions I thought might be reasonable requests.

SMTP Related Questions
install sendmail, sendmail-cf, sendmail-doc (optional)

Q: Configure mail server to accept internet email
A: modify /etc/mail/sendmail.mc
1) cd /etc/mail
2) vi /etc/mail/sendmail.mc
search for 127.0, put dnl at the front of the line
3) make
or m4 sendmail.mc > sendmail.cf
service sendmail restart
Q: Mail alias
A: modify /etc/aliases, run newaliases
Q: Receive mail for DomainX.example.com
A: modify sendmail mc as above, and add domain to /etc/mail/local-host-names
domainx.example.com
Debugging:
mail -v root
mailq, mailq -Ac
sendmail -q
tail -f /var/log/maillog

Configure Sendmail as a Server for Other Clients

A little more detail...

    as root, or sudo
  1. backup your /etc/mail/sendmail.mc and sendmail.cf files
  2. vi /etc/mail/sendmail.mc

  3. Search for a line with 127, and comment the line by placing "dnl #" at the beginning
    Change this line
    DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
    to this
    dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
  4. m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

  5. /sbin/service sendmail restart

  6. /sbin/chkconfig sendmail on

Debugging:
mail -v root
mailq, mailq -Ac
sendmail -q
tail -f /var/log/maillog

Links
For more details, see the Red Hat Reference Guide
https://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/ref-guide/s1-email-mta.html

And LinuxSelfHelp
http://www.linuxselfhelp.com/quick/sendmail.html

How to Run a Bash Command on All Items in a List

For Linux / Unix
Follow as instructed

For Windows
Download cygwin from http://cygwin.com
For instructions, see this article: http://systemnotesorg.blogspot.com/2007/04/use-cygwin-to-run-linux-on-windows.html

Two Easy Steps for One-Liners

e.g., you have a list of servers, and would like to do something, such as ping each one, or check their IP address. Here is a quick two-step process, with a one-line shell script that can be run from the command line.

1) Create a Text file, with one hostname per line
2) Run a for loop on the file

$ cat servers.txt
server01
server02
server03

$ for host in `cat servers.txt`;do host $host;done
server01.example.com has address 10.10.10.10
server02.example.com has address 10.10.10.11
server03.example.com has address 10.10.10.12
$

If you want different output, you can use awk, but that's another topic.

Notice a few things about this one line script.
1) Each command is separated by a semicolon ";"
2) The back ticks around a command and parameter causes the results to be returned
3) The variable host is assigned in the first part, and called just before done

Note: if you want to use ping, try "ping -c 1 $host", or it will never finish.

Use Cygwin to Run Linux on Windows

Yes, not only can you run Linux from a CD --
http://systemnotesorg.blogspot.com/2007/04/how-to-get-started-with-linux.html, but you can also install it in Windows, and run it as a Windows
program. You get a standard linux bash shell, and even X, with a little
configuration.

What Is Cygwin? (from http://cygwin.com)


  • Cygwin is a Linux-like environment for Windows. It consists of two
    parts: A DLL (cygwin1.dll) which acts as a Linux API emulation layer
    providing substantial Linux API functionality.

  • A collection of tools which provide Linux look and feel.
The Cygwin DLL currently works with all recent, commercially released

x86 32 bit and 64 bit versions of Windows, with the exception of Windows CE.

Note that the official support for Windows 95, Windows 98, and Windows Me will be discontinued with the next major version (1.7.0) of Cygwin.

What Isn't Cygwin?
  • Cygwin is not a way to run native linux apps on Windows. You have to
    rebuild your application from source if you want it to run on Windows.

  • Cygwin is not a way to magically make native Windows apps aware of
    UNIX (r) functionality, like signals, ptys, etc. Again, you need to
    build your apps from source if you want to take advantage of Cygwin
    functionality.

Where to Get Cygwin
http://cygwin.com/
http://freshmeat.net/projects/cygwin/
http://sources.redhat.com/cygwin/

How to Install Cygwin
1) Download the installer
2) Run the installer
3) Select some mirrors near you
4) Select applications to install, or just leave the default
5) Finish
6) Run cygwin (double-click on the icon)
7) Enjoy!


Support for Cygwin
RedHat -- for Cygwin licensing or commercial support http://www.redhat.com/software/cygwin/
Cygwin FAQ -- http://cygwin.com/faq/
Cygwin Users Guide -- http://sources.redhat.com/cygwin/cygwin-ug-net/

Wednesday, April 25, 2007

Which Certifications are Important?

CNE
Not as popular as it once was.

MCSE
One of the most popular has been the MCSE.

CCNA
It is always good to have some network knowledge.

RHCE
One of the most challenging exams in the industry. All hands-on lab
exam.

A+
Not very difficult, but shows some knowledge of hardware, and is a
prerequsite for HP exams

HP APS
HP Acredited Platform Specialist. Requires CNE, or MCSE and A+ as
prerequsites, but is a fairly easy exam that deals mainly with hardware.

Other Specialties
Oracle, Citrix, etc.

There is plenty of demand for MCSE's, but experience counts as well.
RHCE is another important one, as is the CCNA. Other certs are useful,
but more so in smaller companies, or as a consultant. You will need
more experience to get into a big company, but jobs tend to be more
specialized. You would either be a server admin, network admin, or dba,
whereas in a smaller company you might be all three.

Another important thing to help get interviews is a college degree. You
can use some of your certifications for college credit.
http://systemnotesorg.blogspot.com/2007/03/college-credit-for-it-certifications.html

How to Get Started with Linux

Have you always wanted to find out more about linux, but were not sure where to start? Here is a little information on where to find, and how to run and / or install a linux distribution.

What is Linux?

Linux is the kernel, or core part of an operating system that is free from any software licenses. Free to download, and install on as many machines as you like.

Here's an explanation from http://www.gnu.org/

The GNU Operating System - Free as in Freedom
What is the GNU project?

The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system. Variants of the GNU operating system, which use the kernel called Linux, are now widely used; though these systems are often referred to as "Linux", they are more accurately called GNU/Linux systems.

GNU is a recursive acronym for "GNU's Not Unix"; it is pronounced guh-noo, approximately like canoe.

Trying Linux

First, you may not have known that you don't have to install linux to try it out. Just look for a live cd distro, download the .iso file, burn it to a DVD, or CD, and then boot from the DVD. When you are finished playing around, just pop the DVD out, reboot, and your old OS will come up as before. Of course the computer will run slower from DVD, but it is a good way to get a feel for which distro you like. Some of the more popular live distros are ubuntu http://www.ubuntu.com, and knoppix http://www.knoppix.org (click on the flag for English, or whatever language you prefer). Once you've had a taste, you may want to install it by itself, or as a dual-boot configuration. There are some good howtos, but some of them are outdated. These look pretty good.
http://www.howtoforge.com/windows_linux_dual_boot
http://highlandsun.com/hyc/linuxboot.html
http://www.linuxdevcenter.com/pub/a/linux/2006/05/08/dual-boot-laptop.html

Finding a Linux Distribution

If you want to work as a sysadmin, you really should learn RedHat linux -- https://www.redhat.com/, but you don't have to pay for it unless you want support. You can start by downloading Fedora Core -- http://fedoraproject.org/wiki/. Another popular business distro is SUSE which is now owned by Novell -- http://download.novell.com

Live CD List
http://www.frozentech.com/content/livecd.php

Top Ten Distributions
http://distrowatch.com/dwres.php?resource=major

Choosing a desktop Linux distro
http://www.desktoplinux.com/articles/AT3269115798.html

If you have trouble downloading, you can always buy CDs or DVDs for a very small fee.
http://www.frozentech.com

Finding More Linux Information

RedHat has some very good documentation on their website -- https://www.redhat.com/docs. For example, The Red Hat Enterprise Linux 4 - System Administration Guide is available in HTML and PDF formats: https://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/sysadmin-guide/

Another good source of information is the Linux Documentation Project -- http://en.tldp.org

If you want more interactive help try http://www.linuxquestions.org or a local Linux User Group, known as a LUG, such as KPLUG -- Kernel Panic Linux User Group http://www.kernel-panic.org You can sign up for the mailing list of most LUGs. Some have more traffic than others. This particular LUG happens to have a linux-newbie list for beginners, and they are quite friendly, and very good at answering questions.

And don't forget the ever important google search, using http://www.google.com/linux -- http://systemnotesorg.blogspot.com/2007/03/topic-specific-searches-in-google.html


Tuesday, April 24, 2007

How to Start a Blog

...and maybe make some money.
An article I posted on http://systemnotesorg.blogspot.com discusses how to get more traffic to your site.

http://systemnotesorg.blogspot.com/2007/04/search-engine-optimization.html

Now let's concentrate on how to set up a blog. With blogger, you don't have to know any html, but if you do, it helps.


Getting Started
First go to http://www.blogger.com and create a blog. If you already have a gmail account, you have completed the first step. It is really simple, and they walk you through it. Think of a name, and what you would like to write about.


O.K., so you have a blog, now what?
There is a book title that should help you keep on topic -- "No One Cares What You Had for Lunch" Then start posting. You can set up your blog to receive email, so posting is very easy. Just send an email to the address you set up under settings / email.


Making money
Well, keep posting something useful, but If you want to make money, don't waste any time. Get an adsense account, and start placing some ads on your site.



http://www.google.com/adsense/

Go to the AdSense Setup tab, and select the ads you would like to display. Then just copy and paste the code into your site (use the Template tab in blogger).


For more tips, see some articles on problogger.net -- http://www.problogger.net/how-to-make-money-blogging/
--http://www.problogger.net/archives/2005/12/06/how-bloggers-make-money-from-blogs/, or do a google search on "monetize blog." Here is another link: http://www.stevepavlina.com/blog/2006/05/how-to-make-money-from-your-blog/


Checking Traffic
It is also a good idea to check on your traffic. That can be done easiy by getting a google analytics account. Just copy and paste the code into your site.
http://www.google.com/analytics


For more information about blogs, check out this page.

http://systemnotes.org/blog/

Tuesday, April 17, 2007

Search Engine Optimization

Sure this blog is more about systems and programming than it is about marketing, but if you're building a website or blog, you probably have at least some interest in SEO (Search Engine Optimization). Basically, that means having other quality sites link back to your site, which is what makes it appear higher in search engines such as google

Here are some things to check out:

Try a google search on seo, if you want to learn more.

And don't forget about the excellent webmaster tools at google. http://www.google.com/support/webmasters
and specifically, How can I improve my site's ranking? -- http://www.google.com/support/webmasters/bin/answer.py?answer=34432&hl=en

Thursday, April 12, 2007

Using bash and sed to Modify a Text File

This shell script demonstrates how to write to a text file, and then modify the contents.
#!/bin/sh
# modfile.sh
# by ScottM, 04/12/2007
# demonstrates writing text to a file, and then using sed to modify it.

TESTFILE=test.txt
FRUIT=banana

# add some content to the file (note: file will be overwritten)
echo "apple" > $TESTFILE

# modify the content
sed -e "s/apple/& $FRUIT/g" -i $TESTFILE

# sed uses the "s" option, which uses regular expressions to search and replace text
# "s/apple/" means search for any lines that contain the characters "apple"
# "& " means use the results of whatever was found
# "/& $FRUIT/g"  -- replace "apple" with "apple banana",
# the g is for global, or all lines containing the pattern

# output:
# $ cat test.txt
# apple banana
# $
Sed One Liner

This is really only a one line script, commonly referred to as a on-liner, so we don't really need a bash script, as long as we understand the regular expressions we are trying to use.

From the command line, we can insert a word:

$ sed -e 's/apple/& pear/g' test.txt
apple pear banana

Notice how the ampersand "&" character prints the text that was found.  Note that we left out the -i, so we can test the output before modifying the original.
Look at the difference here.  The word "pear" is either inserted or appended:

$ sed -e 's/\(apple\)/& pear/g' test.txt
apple pear banana

$ sed -e 's/\(apple.*\)/& pear/g' test.txt
apple banana pear

The parenthesis contain the search parameter that is printed by ampersand, but when we include ".*", we get apple followed by all characters up to the end of the line, and then we add a space and out new text:  " pear".

If we want to replace the entire line with the search string, plus some added text we could use the "^" to indicate start of line and $ to indicate end of line. In this case it would use whatever matches the search pattern, and ignore whatever else is on the line.

sed -e 's/^\(apple\).*$/\1 pear/g' test.txt
apple pear

So what happened to banana? We did a search for apple, and surrounded it with parenthesis. Then we asked to print \1 which is the first set of parenthesis (in this case the only set). That effectively erased everything else on the line except whatever matches apple.

Notice how you can print multiple search groups:

$ sed -e 's/^\(apple\)\(.*\)$/\1 pear \1\2/g' test.txt
apple pear apple banana

Exercises
Exercise to try: -- Where this might be useful is when replacing a URL in an html file. Search for href="something", and replace it with href="something-else"

Exercise 2 Try adding other words that match apple (e.g. apples, apple-pie,), and see what happens.

For more Regular Expression examples see our regex articles.

Wednesday, April 11, 2007

HowTo Install Multi Gnome Terminal using Yum

Multi Gnome Terminal Install

Note: This procedure is for non-standard, unsupported software. The dag repository is outside of Redhat's control, but has some very useful software.

Since multi-gnome-terminal has several dependencies, it is easier to install using yum.


First, Install Yum


* Install yum from your distribution
$ rpm -Uvh
/RPMS/rhel-3-i386-as/yum-2.2.0-1.noarch.rpm
* Modify /etc/yum.conf
Standard yum.conf for rhel-3-U6 (change as required):

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=0

[rhel-3-U6-i386-as]
name=Red Hat Enterprise Linux 3 Update 6 i386 AS
baseurl=http://yum.mydomain.com/rhel-3-U6-i386-as/

* Then, add the dag repository to /etc/yum.conf

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el3/en/i386/dag


Now, Install and Configure multi-gnome-terminal


1. Install multi-gnome-terminal
1. yum install multi-gnome-terminal
2. Add launcher to task bar
1. Name: multi-gnome-terminal
2. Command: /usr/bin/multi-gnome-terminal
3. Icon:
/usr/share/pixmaps/multi-gnome-terminal.png
3. Launch multi-gnome-terminal
1. multi-gnome-terminal &
2. or click on launcher icon
4. Configure Console Colors
1. On the "Settings" menu, select "Tab Preferences"
2. Select the "Colors" tab
3. On the Forground/background color drop-down, select "black on white"
4. Select the "Image" tab
5. Check "Shaded Background", and make it less than -50%, so it is almost white
6. Select a background pixmap, if desired
5. Configure keybindings
1. On the "Settings" menu, select "Keybindings"
2. Under the Action Dropdown box, select
1. "Shell->New Tab"
2. Press the keys, "Ctrl-Shift-t"
3. Click on the add button
4. Click on the clear button under the Keybinding label
5. "Shell->HSplit"
6. Press the keys, "Ctrl-Shift-h"
7. Click on the add button
8. Click on the clear button under the Keybinding label
9. "Go Right"
10. Press the keys, "Ctrl-Page Down"
11. Click on the add button
12. Click on the clear button under the Keybinding label
13. "Go Left"
14. Press the keys, "Ctrl-Page Up"
15. Click on the add button
16. Click on the clear button under the Keybinding label
17. "All bonded"
18. Press the keys, "Ctrl-Alt-b"
19. Click on the add button
20. Click on the clear button under the Keybinding label
21. "All unbonded"
22. Press the keys, "Ctrl-Alt-u"
23. Click on the add button
24. Click on the clear button under the Keybinding label
3. Click on the OK button


Why so much configuration?


It is really optional, but the steps listed make the program function like a normal gnome-termial window, so the appearance and keystrokes will be similar. Of course, you are welcome to configure it however you want.

Monday, April 2, 2007

Using nmap to Generate Host Lists

An easy way to get a list of hosts from a single domain that you are a part of, is to query DNS

host -l mydomain.com

But that is not always practical. Sometimes you have machines that are in different domains, but they all are part of a network you manage. Rather than trying write a script that pings hosts and reports the output, just use nmap for a very fast scan.

To scan all hosts in a list of subnets

1) Create a subnets.dat file with one subnet on each line:

$ cat subnets.dat
192.168.0.*
192.168.1.*

2) Run nmap with the subnets.dat file as input

$ nmap -sP -R -iL subnets.dat
Reading target specifications from FILE: subnets.dat

Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Host (192.168.0.0) appears to be down.
Host box1.mydomain.com (192.168.0.1) appears to be up.
Host box2.mydomain.com (192.168.0.2) appears to be down.
Host box3.mydomain.com (192.168.0.3) appears to be up.
Host (192.168.0.4) appears to be up.
...

Notice how names are resolved for existing hosts, but only an IP is returned, if there is no DNS record (e.g. 192.168.0.0).

3) Write a script to report on the output you want
e.g. for a list of all hosts that respond to ping

$ cat nmap_servers.sh
#!/bin/sh
OUTFILE=hosts_scanned.dat

# clean up old file
[ -f hosts_scanned.dat ] && rm hosts_scanned.dat
echo "nmap -sP -R -iL subnets.dat | grep "to be up" | awk '{print \$2}' "
echo ""

# write all hosts to file, but print only hosts that appear to be up.
nmap -sP -R -iL subnets.dat -oN $OUTFILE | grep "to be up" | awk '{print $2}'

Of course this output can always be redirected to a file, if desired. The output file "hosts_scanned.dat" will contain any host nmap found in DNS, and whether it was up or down.

----------
Sample output after grep and awk:
box1.mydomain.com
box3.mydomain.com
(192.168.0.4)

Notice that I use awk to print the second field. That's because some entries might have an IP address, but not a DNS entry. So the second field is whatever comes after Host, which is either an IP address, or a hostname. In this case, I want to find any IP's without hostnames, so I can fix DNS, but you may want to just keep the ip in the list,so you can ssh to it later.

To get rid of the parenthesis, I redirected the output to hosts_up.dat, and piped the output to grep and awk to illustrate:

cat hosts_up.dat | grep \( | awk -F[\(\)] '{print $2}

More detail on these commands will be posted on http://www.systemnotes.org/linux