www.tiburonfour/computer
Quick reference for the road...
Linux - Helpful Commands
NetworkingNetstat -an (active tcp sessions)
route add default gw 192.168.12.2
ifconfig eth0 192.168.12.10 netmask 255.255.255.0 up
ifup eth0
Redhat IP Addressing
netconfig or ifconfig (temporary)
Red Hat Linux keeps the network settings in the file /etc/sysconfig/network
To use the DNS you need to list one or more nameservers, by IP address, in the file /etc/reslove.conf
If you have more than one Network Interface Card (NIC), as for example a laptop with both a wired and wireless connection, then information for each NIC will appear in separate files in this directory with names of the form ifcfg-ethX for "eth0" and "eth1", etc. For example, to enable DHCP at boot for a wireless card which is "eth1" the file would contain:
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=DHCP
Figure 2: The file /etc/sysconfig/network-scripts/ifcfg-eth1 for a wireless NIC, as in a laptop.
DHCP Issues
To work around this problem, become root (su -) and use a text editor to edit the following files in the guest operating system:
/etc/sysconfig/network-scripts/ifcfg-eth<n>
/etc/sysconfig/networking/devices/ifcfg-eth<n>
Also, if it exists, edit the file
/etc/sysconfig/networking/profiles/default/ifcfg-eth0
The third file is updated any time you run redhat-config-network and
make changes in the Network Configuration panel.
In all cases, <n> is the number of the Ethernet adapter — for example, eth0.
In each of the files, add the following section:
check_link_down () {
return 1;
}
Then run the command ifup eth<n> (where <n> is the number of the Ethernet adapter) or restart the guest operating system.
Note: If you later run redhat-config-network again, check the file
/etc/sysconfig/networking/profiles/default/ifcfg-eth0 to be sure the section your added to it remains intact. In some circumstances, the
closing curly brace — the } character — may be dropped when you use the Network Configuration panel.
SSH
sshd2 should be located in the /etc/rc.d/init.d directory, and there should be symbolic links to sshd2 startup script in /etc/rc.d/rc?.d, where "?" is the runlevel.
You can either add these links manually or use chkconfig.
sshd service startup
install it in /etc/rc.d/init.d, then run "chkconfig --add sshd" if this is Red Hat Linux
NTP
Ensure that ntpd runs at system boot. For example, on RedHat Linux:
# chkconfig ntpd on
Runlevels
A state, or mode, defined by the services listed in the SysV /etc/rc.d/rc<x>.d/ directory, where <x> is the number of the runlevel.
The idea behind SysV init runlevels revolves around the fact that different systems can be used in a different ways. For example, a server runs more efficiently without the drag on system resources created by the X Window System. Other times, a system administrator may need to operate the system at a lower runlevel to perform diagnostic tasks, like fixing disk corruption in runlevel 1, when no other users can possibly be on the system.
The characteristics of a given runlevel determines which services are halted and started by init. For instance, runlevel 1 (single user mode) halts any network services, while runlevel 3 starts these services. By assigning specific services to be halted or started on a given runlevel, init can quickly change the mode of the machine without the user manually stopping and starting services.
The following runlevels are defined by default for Red Hat Linux:
*
0 — Halt
*
1 — Single-user text mode
*
2 — Not used (user-definable)
*
3 — Full multi-user text mode
*
4 — Not used (user-definable)
*
5 — Full multi-user graphical mode (with an X-based login screen)
*
6 — Reboot
In general, users operate Red Hat Linux at runlevel 3 or runlevel 5 — both full multi-user modes. Users sometimes customize runlevels 2 and 4 to meet specific needs. since they are not used.
The default runlevel for the system is listed in /etc/inittab. To find out the default runlevel for a system, look for the line similar to the one below near the top of /etc/inittab:
id:5:initdefault:
The default runlevel listed in the example above is five, as the number after the first colon indicates. To change it, edit /etc/inittab as root.
Files and User Management
useradd or adduser command (should give you a wizard)
Othewise adduser -u scott
passwd scott #prompts for a new password for scott
Mounting NFS Shares:
Export on Filer
mkdir /mnt/mnt4
mount setrainer:/vol/vol0/mnt4
Example: Adding User "scott" into new directory /export/scott with bash shell
# mkdir /export/scott
# useradd
UX: useradd: ERROR: invalid syntax.
usage: useradd [-u uid [-o] | -g group | -G group[[,group]...] | -d dir |
-s shell | -c comment | -m [-k skel_dir] | -f inactive |
-e expire | -A authorization [, authorization ...] |
-P profile [, profile ...] | -R role [, role ...]]
-p project [, project ...] login
useradd -D [-g group | -b base_dir | -f inactive | -e expire
-A authorization [, authorization ...] |
-P profile [, profile ...] | -R role [, role ...]] |
-p project
# useradd -d /export/scott -s /bin/bash scott
# passwd scott
New Password:
Re-enter new Password:
passwd: password successfully changed for scott
#
# chown scott
usage: chown [-fhR] owner[:group] file...
# chown scott /export/scott
#
# su scott
bash-2.05$
bash-2.05$
bash-2.05$ pwd
/xxx
bash-2.05$ exit
# su - scott
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
bash-2.05$
bash-2.05$
bash-2.05$ pwd
/export/scott
bash-2.05$
Mounting hardware
mount /dev/cdrom /mnt/cdrom
(mounting a cdrom on linux, virtual pc for me)
"eject /mnt/cdrom" to force a umount and eject.
Probe for new hardware
#kudzu -p
[root@linuxboy mnt]# showmount -e 10.41.77.149
Export list for 10.41.77.149:
/vol/autodesk (everyone)
/vol/vol0/home (everyone)
/vol/vol0 10.41.77.101,10.41.77.182
[root@linuxboy mnt]# showmount 10.41.77.149
Hosts on 10.41.77.149:
10.41.77.146
Date
#date 0101010004
This would set the date to January 1 (0101), 1 a.m. (0100), 2004
Misc.
Gunzip a file
Tar xvf filename.tar = untars a file
tar -xvf
find / -name "create_mysql" -print
rm filename = remove file
free = amount of memory available
pwconv = takes the /etc/passwd file, and generates shadow entries in /etc/shadow
pwd = print working directory
cd = with no arguments, puts you in home directory
$ cd .. #This is shorthand for go back one step in the directory tree (just like in DOS).
$ cd ~ #This is for /home/scott
mkdir something or full path name = makes a directory
rmdir
ls -a = lists everything
ls -l = lists long verbose
ls inv?jig
ls inv*jig
. = current directory
..= directory above it
cat filename = scan file quickly rather than edit
more filename =
& runs a program in the background
Shutdown immediately:
shutdown -h now
Reboot immediately:
shutdown -r now
Shutdown at 8 pm:
shutdown -h 20:00
Shutdown in 10 minutes:
shutdown -h +10
RPM Packages
get packages
ftp.redhat.com/pub/redhat/linux/9/en/os/i386/RedHat/RPMS/
www.tfug.org/helpdesk/linux/rpm.html
rpm -ivh xsnow-1.40-5.i386.rpm
The -i is the install switch. I like to use the v for verbose messages in case if the installation fails. The h option shows our progress with hash marks. If nothing else, it entertains you while your package is installed.
Installing mysql on BSD:
Pkg_add –r portsnap
Portsnap fetch
Portsnap update / portsnap extract
Cd /usr/ports/databases/mysql40-server
Make install
mkdir usb
mount /dev/sda1 usb
The mount command will take some time. It should (almost) always be sda1,
but you can check by running
dmesg
and reading the last few lines after you insert the device. Mine says
something like:
hub.c: new USB device 00:07.2-1, assigned address 3
WARNING: USB Mass Storage data integrity not assured
USB Mass Storage device found at 3
SCSI device sda: 512000 512-byte hdwr sectors (262 MB)
usb-uhci.c: interrupt, status 3, frame# 1066
sda: Write Protect is off
sda: sda1
MD5
::md5::md5 msg
The command takes a message and returns the MD5 digest of this message as a hexadecimal string.
::md5::hmac key text
The command takes a key string and a text and returns the hmac of the text under the chosen key as a hexadecimal string.
EXAMPLES
% md5::md5 "hello world"
5eb63bbbe01eeed093cb22bb8f5acdc3
% md5::hmac "our little secret" "hello world"
61a922114c8aaf5050098be6d3a7daf0
Lost User Password
So you forgot your user password, eh? The following steps assume you've forgotten your user password but remember your root password. If you don't remember your root password, skip down to that section.
Start by logging in as root. (If you're not sure how to do that, read Logging in and out as Root on LinuxClues.com.) Next, open a terminal or console and type the three lines that follow. (Remember, don't type the pound symbol, that shows you're logged in as root.)
# passwd {type your username here without the curly brackets}
Type in a new password (Ignore the error message you'll probably get.)
Type in the new password again.
Log out as root and back in as user with your new password.
Of course, this fix assumes you remember your root password. What do you do if you forget your root password? Not possible? Ok, just imagine you disappear on a fantastic vacation, sans PC. (It COULD happen.) Let's say you spend a glorious two weeks of baking your brains in the sun, or hiking up the sides of mountains viewing stunning vistas. Day after day after day. Then after 14 days of this you head back home, where you power up the PC, go to login and have brain fade trying to remember your root password. What should you do? Well, we'll show you.
Lost Root Password
IMPORTANT: Physically disconnect your PC from the network and the Internet -- pull the Ethernet cable out, eject the wireless card, whatever. Just make sure you're offline. This is to protect your PC from possible Internet-borne attack while you're repairing the password. Please heed this warning and follow this safety procedure. Linux is vulnerable during these steps.
Follow this two-step process. Because the first step varies from distro to distro, we're presenting several alternatives, including an advanced version. The second step is pretty much the same across the board.
Step 1: Red Hat and Mandrake
Start with install CD #1 and boot with it. As the first screen appears, press F2 and type:
rescue (Type "linux rescue" for Red Hat.)
The computer should boot into rescue mode. The screen will display several options. Select: "mount the existing partitions" and go to the shell/console prompt. (Mandrake users: Boot into "failsafe" from the Lilo menu instead.)
Step 1: SuSE
Boot from your first install CD and press F1 at the first screen, then choose "Rescue System" from the menu and at the prompt type:
root (You do not need a password.)
Step 1: Other Distros
Boot from your first install CD (or any live CD like Knoppix) and at the boot prompt type:
linux single (For Knoppix type "knoppix single" without the quotes.)
The computer will boot in single user mode. You will see an odd looking prompt that might look something like: "sh-2.05b#".
Step 1: Advanced Alternative
If you're a regular reader of Scot's Newsletter and you carried out the Rescue CD Linux Explorers tip from the last newsletter issue, you already have a Linux rescue CD, which is required for this alternative to Step 1.
By booting with your rescue CD (or to a live Linux CD, such as Knoppix), you can bypass Step 1, mount the partition and, while logged in as root, skip right to Step 2 and make the changes to the files Step 2 requires.
Step 2
After following Step 1 as appropriate, type the following at the prompt:
# cd /etc (For Knoppix, first you must change directory to the partition with your lost-password distro.)
Step 2 requires you to make changes to these two files: "passwd" and "shadow." Type this line:
# vi passwd (This opens the file with the Vi editor.)
Next, press the I key, which places the Vi editor in Insert mode.
For more on the Vi editor, see the Vi Editor edition of Tips for Linux Explorers.
The first line of the passwd file will probably look like this:
root:x:0:0:root:/root:/bin/bash
Carefully delete the "x" after "root:" being sure to leave the colons in place. The first line should now read:
root::0:0:root:/root:/bin/bash
Save the file by pressing the Escape key and then typing:
ZZ
To edit the second file, type:
# vi shadow
Press the I key to place the Vi editor in Insert mode.
The first line of the shadow file is a long scrambled string of characters. Change it to:
root:::: (That's four colons.)
Save the file by pressing the Escape key and then typing:
ZZ
Now you can reboot your computer. Log in as your normal user, open a console, and type:
$ su
# passwd
And set the new root password. Log out as root:
Ctrl-D
And the job is done!
Congratulations! You've now reset your lost password.
creating unix files
1) touch foo
2) or cat
To create a file with 'cat', type cat and the redirection character ">" (greater-than) and a file name. Everything from Standard In (STDIN) eg. everything you type (or paste in a copy/paste operation) then gets written to the file until a CTRL-D is typed. The file will be created if it does not already exist or overwritten if it already exists. If you use double greater-than as in "cat >>" and a file-name the file will be appended to rather than overwritten.
Some examples:
cat > newwork.text (then type whatever you want in the file and finish with a CTRL-D)
write everything that is typed following the 'cat > newwork.text' command, up to but not including the CTRL-D, in to the file 'newwork.text' Either create a new file 'newwork.text' or overwrite it if one exists.
cat >> addwork.text (then type whatever you want in the file and finish with a CTRL-D)
Append everything that is typed following the 'cat > addwork.text' command, up to but not including the CTRL-D, to the end of file 'addwork.text' Append to an existing file 'addwork.text' if it exists. Create it if it does not already exist.
cat > screen.text (then highlight a piece of screen text with the left button and write it back with the middle button) CTRL-D
copy everything in the highlighted section of screen text to the file screen.text. Either create a new file 'screen.text' or overwrite it if one exists.
cat >> screen.text (then highlight a piece of screen text with the left button and write it back with the middle button) CTRL-D
copy everything in the highlighted section of screen text and append to the end of the existing file screen.text. If it does not already exist, create it.
cat filea fileb filec > combo-file
Copy everything from files 'filea', 'fileb', 'filec' in to 'combo-file' Either create a new file 'combo-file' or overwrite it if it already exists.
cat filea fileb filec >> combo-file
Copy everything from files 'filea', 'fileb', 'filec' and append to the end of the existing file 'combo-file'. If 'combo-file' does not exist, create it.
cat /dev/null > empty-file
Create an empty file called 'empty-file. If a file by that name already exists, empty it out.
(Note: '/dev/null' is a special null device on UNIX systems.)
To modify the user environment on Red Hat Linux:
1.
As the oracle user, modify the user profile in the /home/oracle directory using the following commands:
[oracle] $ cd $HOME
[oracle] $ vi .bash_profile
Add the following lines at the end of the file:
export ORACLE_SID=sales
export PATH=$PATH:$ORACLE_HOME/bin
2.
Read and execute the changes made to the .bash_profile file:
source .bash_profile
Note: You can add any command to the user's profile. That command will execute automatically when the user logs in.
[ Back to top ]
Windows
Remotely
enable remote desktop
Remote Desktop Enabler is a tool from IntelliAdmin that makes the process of remotely enabling remote desktop as easy as entering some information on a form (target machine name, and authentication credentials) and clicking a submit button.
Let me say, while this could be a huge time saver - I always recommend knowing how to crawl before you learn how to run. In other words, learn to do this without using a third party applicaiton before you start taking shortcuts. (InteliAdmin incorrectly states “There is nothing within windows that will allow you to enable this feature remotely.) Here’s how to do it without a tool:
- Open the registry editor (Start > Run > “regedit” > OK)
- In Regedit, connect to a remote computer by selecting File > Connect Network Registry
- Enter the name of the computer you are attempting to remotely enable remote desktop, and click OK
- Find this registry key: HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
- Change the value of the key fDenyTSConnection from 1 to 0 and click OK.
[ Back to top ]
Network Appliance
Multiprotocol
configuration
Add user "scott s" whose username is scott with password Test123, UID
1000 and GID100:
webvan1*> cifs passwd Test123
password is _J9..uoeH8oys8AAUIjs
/etc/passwd entry = scott:_J9..uoeH8oys8AAUIjs:1000:100:Scott S
(password is actually unecessary, username is only here for mapping
purposes)
usermap.cfg = SVSELAB\Administrator <= scott
/etc/exports - Export
to everyone, but only allow
certain hosts to be root:
/vol/myvol/myqtree -root=host1:host2:host3
webvan1> vol create multiprotocol aggr0 10g
webvan1> qtree
qtree: This command is deprecated; using qtree status.
Volume Tree
Style Oplocks Status
-------- -------- ----- -------- ---------
vol0
unix enabled normal
multiprotocol ntfs enabled normal
webvan1> cifs shares -add multiprotocol /vol/multiprotocol
webvan1> exportfs
/vol/multiprotocol
-sec=sys,rw,nosuid
/vol/vol0
-sec=sys,rw=10.41.77.101:10.41.77.182
[scott@linuxbox]# mount 10.41.77.149:/vol/multiprotocol /filer
webvan1> wcc -d
scott (UID 501) from 10.41.77.182 => SVSELAB\scott*
troubleshooting: options cifs.trace_login on
usermap.cfg - When looking for matches the table is scanned sequentially, and the first successful mapping is the one used. The option "wafl.default_unix_user" allows you to specify the name of a UNIX account to use if nothing is matched in the usermap and the lower-cased NT account name does not appear in the UNIX password database. The corresponding option "wafl.default_nt_user" is available to supply a default NT account in case the UNIX account name is not mapped and does not exist in the filer's home domain. You can use the 'wcc -u' and 'wcc -s' filer console commands to perform tests on your mapping file and verify mappings are as expected.
-----------------
The following outlines the steps for CIFS client access on the filer, as well as instructions for troubleshooting each step:
1. CIFS client (PC request)
access to the data.
Commands to troubleshoot this step: ifstat, netdiag, ping, nbstat (if
using wins).
2. Storage Appliance checks with the
Domain controller for authentication.
Commands to troubleshoot this step: cifs testdc, options
cifs.trace_login, options cifs.trace_dc_connection.
3. Domain controller replies with
authentication or guest.
Commands
to troubleshoot this step: wcc -s <USER_NAME>, wcc -s
<SID>, options cifs.trace_login, cifs lookup
<DOMAIN\USERNAME>(if user is from different domain).
4. If the guest access is denied, unless
"options cifs.guest_account " is enabled.
Commands to troubleshoot this step: Check if "options
cifs.guest_account" is enabled.
5. Storage Appliance Maps NT account to
UNIX user_name.
Commands to troubleshoot this step: check /etc/passwd or
/etc/usermap.cfg or nis info or options wafl.default_unix_user.
6. Storage Appliance compares NT account
information with the Share Access control list (ACL).
Commands to troubleshoot this step: Check cifs shares access from MMC
or command line.
7. Storage Appliance compare NT account
info with file ACL or UNIX username with the file permission.
Commands to troubleshoot this step: Check the qtree security style.
8. If the user has access to the share
and the file, the storage appliance grants access.
--------
stats show -i 1 -n 30 volume:*:total_ops
That should show you the total ops of each volume on your filer,
regardless of aggregate. It might also be interesting to show the
average latencys as well.
stats show -i 1 -n 30 volume:*:read_latency stats show -i 1 -n 30 volume:*:write_latency
The system doing the most ops may not be the volume with the highest latency completing the request.
I usually watch sysstat -us 1 to see disk throughput.
-----
Last updated: 28 JUN 2005
[ Back to top ]