Linux Commands

Note: This is a borrowed list, not my own


 (Linux Backup Information) 


tar -ztvf (filename) view tarbalsl

tar -ztvf (filename) >> filename (will create a file to view contents of tarball) 

tar -ztvf ".tar.gz" | grep "filename" (this will search the tarball)


tar -zxvf (.tar.gz only!) file.tar.gz /path (by default it will unzip to 
you path) example $PWD (current path) /home/jplane> tar -zxvf cool.tar.gz 
will do this /home/jplane/cool> 
---------------------------------------------------------------------------

(Linux Commands)

wall "message" -- send a message to everybody's terminal (broadcasting a message to all) 

dd if=ntbootdisk.img of=/dev/fd0 bs=512 (this will read the image ntbootdisk.img and copy it too the file)

dd if=/dev/hda1 of=/mnt/harddrive (this will take the drive /dev/hda1 and copy it to the image /mnt/harddrive)

kill or killall -9 process (will kill the process) 

find / -name 'tacos' (will start from root / and search for file named tacos)

df -h (check disk space on all mounted harddrives)

fdisk / cfdisk (create and view partition tables)

date -s 'Sat Feb 10 02:59 PST 2001' (setting time on linux machine)

mount -t smbfs -o username=user,passwd=password //server/share /mnt

rm -rf (remove directory and files stored in directory)

elm -f (/var/mail/spool view and read emails) 

uname -a (show current kernel version) 

sendmail -bt -d0 (info on sendmail version and more) 

whereis, locate, and find are all search commands

fg (fore ground) when running a task and using crtl-z to exit that task 
run fg to move between applications.

jobs - list all jobs running in foreground

ps -aux ( show all processes that are being ran on this system)
ps -aux | grep %file% (search for a process that is running) 

## restarting sendmail hashes files as needed. (even aliases) 

makemap hash mailertable < mailertable (run in the /etc/mail directory 
this will refresh the .db table) 

sendmail -bi (run this commands to refresh the /etc/mail/aliases and 
/etc/mail/majordomo.aliases files)

sendmail -q (this command will process all files in the sendmail queue) 

mount /dev/sdb1 /mnt/backup (this will mount the second SCSI drive that 
contains all the backup files and folders"/data & /config"

tar -xvf extract .tar files
tar -cvf archive .tar files 
tar -zxvf extract .tar.gz files
tar -zcvf compress .tar.gz files

tar -cvf %name% /directories
tar -cvf -X %name% /directories 

who - show all users logged in 

last - show the last users logged in ( use last - number to shorten)

talk - used to talk with other users on the system

chown - change the current ownership of a file or folder

chmod - change the file attributes on a system 

chgrp - change group ownership of a file or folder

mkdir - make a directory 

rm - remove a file

rmdir - remove a directory

ln -sf creates a symbolic link to a folder ln -sf test /home now you would be able to change to test and it would link to /home

ln -s filename youname (create a symbolic link to a file)

e2fsck ( use to fix problems with ext2 drives) 

fdisk (use to partition a harddrive) 

mkfs.ext2 ( use after creating a partition with fdisk) 

(SAMBA)

Samba is used to allow Windows Clients to access stuff likes /home 
directories and printers.

# here is a list of problems and resolutions that I've found with Samba

- IPC$ password is being requested on Windows clients - 
check > smbpasswd -a %username% (add user for samba, will need to also be in /passwd) 
check > smbpasswd %username% (change the password for samba users)
check > security = share or user (set this to share) 

- Cannot print even though it can connect and view properties.
check > permissions for spool directory (/etc/printcap) 
check > spool path 
check > restart lpd 
- Password is being requested for printing 
check > 
[printers] 
guest ok = yes 

Samba contains 3 primary sections by default: 

[global]
workgroup = (windows workgroup) 
server string = (name) 
printing = lprng 
[homes]
comment = (windows comment) 
path = /home
writable = yes
guest ok = yes
[printers]
comments = 
path = (spool path) 
printable = yes
browseable = yes
guest ok = yes 


(VNCSERVER)

logon as the user you wish to start vncserver for:
[jplane@proxy jplane]$ vncserver (this will start the vncserver for 
"jplane" and will assign you a number to your host. It will display this 
number once you start the vncserver. 

1> Before connected assign your Xserver a display. Simple just type 
vncpasswd and then it will ask you for a password.

2> On the Windows Client you will enter the number as host:number. 
Example I started the Vncserver and was assigned number 10. I would 
connect to 64.64.222.4:10.

# You may only be able to connect as root. This can be fixed by adding 
full permissions to /tmp/.X11-unix directory.
# Also it is recommend to connect to a VNCserver you have a connection of 
10+ Mbps at least. 

# you will also need to have the following path statement in .bash_profile 
> PATH=/usr/local/bin:/usr/local/sbin:$PATH:$HOME/bin

# Changing you Session manager can be done by editing Xstartup file in 
/home/user/.vnc/Xstartup 
gnome-session 
twm & 
kde & 
startkde & 

(IPChains)

# utility that works ! http://www.pointman.org/PMFirewall PMFirewall ! 

# simple ip chains setup (remember to MASQ first then set "filters")
# MASQ aka NAT

Key:
A = append 
D = delete 
j = rule 
s = source 
d = destination 
L = list
F = flush
R = replace
Z = zero counters to all chains
C = test this packet on chain
N = create a new user defined chain
X = delete a user defined chain
X = list current masquerading connections
p = proto by number or name
s = source 
m = number to mark on matching packet
l = turn on logging 
v = verbose mode
V = version 

> eth0 (internal network) 192.168.1.0/24
> adds rule
! ipchains -A forward -j MASQ -s 192.168.1.0/24 -d 0.0.0.0/0
> delete rule 
! ipchains -D forward -j MASQ -s 192.168.1.0/24 -d 0.0.0.0/0
or delete by using 

! ipchains -R "output/input/or/forward" 1 (number goes here)


! ipchains -F input (flush all input commands)
! ipchains -F output (flush all output commands) 
! ipchains -F forward (flush al forward commands) 

# MASQ 
! echo "1" > /proc/sys/net/ipv4/ip_forward
! ipchains -P forward DENY 
! ipchains -A forward -j MASQ -s x.x.x.x/24 -d 0.0.0.0/0

# ipchains filters

# prevent all ipaddresses from 127.0.0.0/8 from entering machine.
! ipchains -A input -j DENY -p all -l -s 127.0.0.0/8 -i eth0 -d 0.0.0.0/0 
! ipchains -A input -j DENY -p all -l -s 127.0.0.0/8 -i eth1 -d 0.0.0.0/0

# filter by ip address x is the ipaddress you want to block

! ipchains -A input -j DENY -p all -l -s x.x.x.x/x -d 0.0.0.0/0

# filter by port number deny access to port for y.y.y.y machines

! ipchains -A input -j DENY -p tcp -l -s 0.0.0.0/0 -d y.y.y.y/32 port 
! ipchains -A input -j DENY -p tcp -l -s x.x.x.x/x -d y.y.y.y/32 10:100 

# port redirection
! ipchains -A input -j REDIRECT 8080 -p tcp -s 0.0.0.0/0 -d 0.0.0.0/80

# ip accounting

! ipchains -L chain -v 
! ipchains -N acctin
! ipchains -N acctout
! ipchains -N acctio

# adding routing on startup
> create a script that will start the above rules 
> add the following lines to /etc/rc.d/rc.sysinit
if [ -f /sbin/ipchains ] ; then 
/route/./start_route
echo Router is now starting.
fi 

(Cron Daemon)

* Cron is a task schedule that looks in /etc/cron.hourly,daily,weekly,monthly.
* Crond is the daemon that runs in the background. 
* /etc/crontab is the conf file that contains all the info to run jobs and when.

> crontab 
- u username displays the users jobs running
- l displays the current job
- r remove a job
! format of a cron job

/etc/crontab
05 15 01 01 01 /sbin/shutdown -r now

05 = minute
15 = hour
01 = day of the month 
01 = month 
01 = day of the week

/sbin/shutdown -r now = command

** = everyday

if this file where used as jplane

crontab -u jplane jplane.ct

this would save the crontab as jplane.ct

( Sendmail )

sendmail -q will force sendmail to push all the information in the /var/spool/mqueue out!

Relaying 
sendmail relaying is controlled with /etc/mail/access and through /etc/sendmail.cf
example of access file 
localhost RELAY
nicepeople.com RELAY

Relaying denied? - check you access file and restart sendmail 

Make sure you stop and start sendmail after this and also recreate the .db file (makemap hash access > access 

Sendmail old and new filenew support

old filename new filename

/etc/bitdomain /etc/mail/bitdomain
/etc/domaintable /etc/mail/domaintable
/etc/genericstable /etc/mail/genericstable
/etc/uudomain /etc/mail/uudomain 
/etc/virtusertable /etc/mail/virtusertable
/etc/userdb /etc/mail/userdb

/etc/aliaes /etc/mail/aliases
/etc/sendmail/aliases /etc/mail/aliases
/etc/ucbmail/aliases /etc/mail/aliases
/usr/admn/sendmail/aliases /etc/mail/aliases
/usr/lib/aliases /etc/mail/aliases
/usr/ucblib/aliases /etc/mail/aliases

/etc/sendmail.cw /etc/mail/local-host-names
/etc/mail/sendmail.cw /etc/mail/local-host-names
/etc/sendmail/sendmail.cw /etc/mail/local-host-names

/etc/sendmail.ct /etc/mail/trusted-users

/etc/sendmail.oE /etc/mail/error-header

/etc/sendmail.hf /etc/mail/helpfile
/etc/mail/sendmail.hf /etc/mail/helpfile
/usr/ucblib/sendmail.hf /etc/mail/helpfile
/etc/ucbmail/sendmail.hf /etc/mail/helpfile
/usr/lib/sendmail.hf /etc/mail/helpfile
/usr/share/lib/sendmail.hf /etc/mail/helpfile
/usr/share/misc/sendmail.hf /etc/mail/helpfile
/share/misc/sendmail.hf /etc/mail/helpfile

/etc/services.switch /etc/mail/service.switch

/etc/sendmail.st /etc/mail/statistics
/etc/mail/sendmail.st /etc/mail/statistics
/etc/mailer/sendmail.st /etc/mail/statistics
/etc/sendmail/sendmail.st /etc/mail/statistics
/usr/lib/sendmail.st /etc/mail/statistics
/usr/ucblib/sendmail.st /etc/mail/statistics

#Configure access to allow relaying for certain hosts.

access
access.db

# Contains all the aliases for usmicro.com

aliases 
aliases.db

# not being used provided for domain name mappings. User of this should 
really be limited to your own domains. It may be useful if you change 
names.

domaintable 
domaintable.db

# contain a list of domains which we hosts. Formally known as 
/etc/sendmail.cw
local-host-names

# Files contains addresses for customer email addresses to local over 
riding domains 
mailertable 
mailertable.db

# Used in addition to aliases 
majordomo.aliases
majordomo.aliases.db

# sendmail configuration file 
sendmail.mc

# using the same as mailertable (maps incoming users) maps all virtual address into real addresses

# add user@domain.com localhost here for routing 

virtusertable 
virtusertable.db

Info: 
Remember to create DB you must use makemap hash file < file this will 
generate a .db file that is binary format. 


## New Domains with email!

1> Setup the proper configuration in /var/named/missing.com 
2> Configure Users janedoe and johndoe
3> Add missing.com to /etc/mail/local-host-names (5.1 called sendmail.cw)
4> Add Johndoe and Janedoe to /etc/mail/aliases: 


5> Add users to virtusertable (5.1 called maildomains) 

jannie@missing.com jannie
johnny@missing.com johnny

then save and run makemap hash virtusertable < virtusertable 

6> Also add the same above entries to mailertable save and run makemap 
also (not necessarily, only need to add the virtusertable)

Once all these steps have been completed also restart sendmail with 
sendmail -bi command or /etc/rc.d/init.d/./sendmail restart

(Apache)

Creating several websites to connect to one ip address.
Create the VirtualHost tabs in /etc/httpd/conf/httpd.conf and specify the 
Apache Webserver that is running the ip address.

(NFS)

add hosts names to /etc/exports - restart system
/etc/exports
/ (mount point) 10.0.0.17/255.255.255.0(rw) (this will mount 10.0.0.17 and allow read/write access) 
access drive from client by typing 
mount -o wsize,rsize server:/ /mnt
(note: rpc and portmap both need to being running, check status using netstat -na)