Thursday, November 22, 2007

Create MySQL User

To create a user in mysql, issue the following:
CREATE USER 'user'@'host' IDENTIFIED BY 'password';

To create a user in mysql and assign grants, issue the following:

grant privilege on database.table to 'user'@'host' [with grant option] [identified by "password"]

Available privileges:
ALL [PRIVILEGES]
ALTER
CREATE
DELETE
DROP
FILE
INDEX
INSERT
PROCESS
USAGE
RELOAD
SELECT
SHUTDOWN
UPDATE

To revoke privileges:
revoke privilege on database.table from user

To revoke grant option:
revoke grant option on
database.table from user


To change a password:
UPDATE mysql.user SET Password=PASSWORD('password')
WHERE User='someuser';

View current user:
select user();

Show user permissions:
show grants for 'username'@'localhost';


http://www.tech-faq.com/reset-mysql-password.shtml

Reset MYSQL root password

Reset the mysql "root" password:
1) Log in as UNIX root
2) Stop the MySQL Deamon (may vary depending on OS)
/etc/rc.d/init.d/mysqld stop
3) Start mysql in safe mode
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables
4) Log into the mysql schema as root in safe mode
/usr/local/mysql/bin/mysql --user=root mysql
5) Run the update to change the password
UPDATE user SET Password=PASSWORD('YOUR_PASSWORD')
WHERE Host='localhost' AND User='root';
flush privileges;
6) Restart the MySQL server deamon
/etc/rc.d/init.d/mysqld start


Method set a root password
mysqladmin -u root password 'new-password'

http://help.hardhathosting.com/question.php/200

Friday, September 14, 2007

Terminal Information

The $TERM environment variable sets the terminal type. The terminal type environment variable should specify a terminal type definition file that is usually located in the /usr/share/lib/terminfo/ directory. This terminal type in the shell environment should match the terminal type setting in your terminal emulator program (xterm, putty, gterm, secureCRT, etc. ).

Set this environment variable to override default terminfo DB location
TERMINFO

Use this to query a terminfo DB in a nondefault location
infocmp -A /nonstandard/terminfo/DB/location/path

Terminfo default DB location
/usr/share/lib/terminfo

Show differences between terms
infocmp -d vt100 vt220

Show similarities between terms
infocmp -c vt100 vt220

Show term capabilities
infocmp # no args defaults to $TERM var
infocmp -I # no args defaults to $TERM var
infocmp term_name # term_name is a filename in the terminfo DB location
infocmp -1 # one item per line

Print ansi escape sequences for a given terminal capability
tput option # option listed in infocmp output

Compile a terminfo source file to be stored in the TERMINFO dir
tic filename

Create Windows style newline characters from the terminal
type: Ctrl-v Ctrl-m
printf '\r\n'

Display Windows style newline characters
cat -ve filename

Enable color in vim for terminals that support it (xterm, vt100, linux)
Add the following to the ~/.vimrc
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
syntax on

Replace the ^[ with a real key (type CTRL-V ESC)

http://vimdoc.sourceforge.net/htmldoc/syntax.html#xterm-color
http://vim.wikia.com/wiki/Color_highlighting_on_telnet
http://en.wikipedia.org/wiki/Newline

Wednesday, August 22, 2007

Subversion

Setting up a repository:
svnadmin create /usr/local/svn/newrepos

Import files into repository:

svn import /import/dir file:///usr/local/svn/newrepos/projectname -m "comment"

List files in a repository tree:

svn list file:///usr/local/svn/newrepos/projectname
svn ls #while in sandbox
svn ls -v # verbose

Checkout a directory:

svn checkout "http://host:port/path"
svn co http://host:port/path
svn checkout file:///path/to/repos
svn checkout file:///localhost/path/to/repos
svn checkout svn+ssh://host/path/to/repos

Check a specific revision:
svn checkout -r revision_num
svn checkout -r {2006-02-17}
svn checkout -r {"2006-02-17 15:30"}

Checkin a file:
svn commit filename.txt -m "some comment here"

Update working copy with committed changes from other users:
svn update

Manage local copy (sandbox):
svn add filename
svn delete filename
svn move file1 file2
svn copy file1 file2
svn mkdir dirname

View files changed since last commit:
svn stat
svn stat filename
svn status -v # verbose view of all files in sandbox
svn status -v -u # contacts the repository to show more info

View changes since last commit:
svn diff # show diffs within files

Revert a file (working copy):
svn revert file


Restore a previously committed file back to working copy:
svn merge -r curr_version:prev_version working_file.txt

Show revision history:
svn log
svn log -r 5:19 # shows revisions 5 through 19
svn log -r 9 # shows revision 9
svn log filename # show revisions on a given file
svn log -r {2006-11-20}:{2006-11-22} # show versions between two dates
svn log --verbose # show all files in all revisions
svn log --verbose | grep "/path/to/file/" -B10 # grep history and show last 10 lines

Show file info:
svn info filename

Backup a repository:
svnadmin dump
/path/to/repository > dumpfile

Restore a repository:

svnadmin load
/path/to/repository/ < dumpfile.dump

Export a repository without all the metadata:
svn export file:///path/to/repository export_dir

Ignore files in the svn working copy:
create a file in home directory called .svnignore 
While in working copy, run command
svn -R propset svn:ignore -F /path/to/home/.svnignore .


http://pandemoniumillusion.wordpress.com/2008/05/07/ignore-pyc-files-in-subversion/

http://svnbook.red-bean.com/en/1.0/re10.html
http://svnbook.red-bean.com/en/1.0/re36.html
http://aralbalkan.com/1381
http://svnbook.red-bean.com/en/1.1/svn-book.html#svn-ch-3-sect-6.2.2

Sunday, April 22, 2007

Serial to USB converter

Prerequisites
minicom

kernel configure options:
USB=m # USB subsystem
USB_SERIAL=m # USB serial port support
USB_SERIAL_GENERIC=m # USB serial port generic driver
USB_SERIAL_PL2303=m # USB serial port driver

menuconfig path:
- Device Drivers ->
-- USB Support ->
--- USB Serial Converter support ->
---- USB Generic Serial Driver
---- (hardware specific driver)
---- e.x. USB Prolific 2303 Single Port Serial Driver

lsmod Listing (modules loaded):
usbcore pl2303,usbserial,...
- usbserial pl2303

Minicom serial port settings:
Serial Device: /dev/ttyUSB0
Bps/Par/Bits: 9600 8N1
Hardware Flow Control: No
Software Flow Control: No

http://www.gentoo.org/doc/en/usb-guide.xml

Saturday, April 14, 2007

iproute commands

Prerequisites
iproute2 package


kernel configure options:

CONFIG_IP_ADVANCED_ROUTER=y
CONFIG_IP_MULTIPLE_TABLES=y
CONFIG_IP_ROUTE_MULTIPATH=y

menuconfig path:
- Networking -->
-- Networking Support -->
--- Networking options -->
---- TCP/IP networking
----- IP: Advanced router
----- IP: policy routing
----- IP: equal cost multipath


Enable IP Forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter

IP LINK
(cmd subset)

Show hardware address

ip link
ip link [show|ls|list|sh]

Take an interface up/down
ip link set dev (device) up
ip link set (device) up
ip link set dev (device) down
ip link set (device) up

Change the MAC address of the interface
ip link set dev (device) address (arp address)


IP ADDRESS (cmd subset)

Show ip address
ip addr
ip addr [show|sh|list|ls]
ip addr show dev eth0 # show specific device

Show ip addresses (the old "ifconfig" way)
ifconfig -a
ifconfig

Assign IP address to interface
ip addr [add|a] (address)/(mask) dev (device)
ex: ip addr add 192.168.1.2/24 dev eth0

Assign IP address to interface (the old "ifconfig" way)
ifconfig eth0 192.168.1.2 netmask 255.255.255.0

Remove IP address from interface
ip addr [delete|del|d] (address)/(mask) dev (device)
ex: ip addr del 192.168.1.2/24 dev eth0


IP NEIGHBOR (cmd subset)

Show ip Layer 2 neighbors (arp table)
ip neigh

Show ip Layer 2 netighbors (the old "arp" way)
arp -a

Add new ARP mapping
ip neigh add 192.168.1.100 dev eth0 lladdr (mac address)
ip neigh add 192.168.1.100 dev eth0 lladdr (mac address) nud reachable

NUD Statuses
--permanent (perm) # administrative mapping
--noarp # neighbor valid but no attempt to rearp will be made
--reachable # neighbor entry valid until timeout
--stale # old arp entry

Remove ARP mapping
ip neigh del 192.168.1.100 dev eth0

Flush arp table
ip neigh flush


IP ROUTE
(cmd subset)

Show ip routing tables

ip route

Show ip routing tabes (the old "route" way)
route

Add Static Route
ip route add (network)/(mask) via (ip to route through)
e.x. ip route add 10.0.0.0/24 via 192.244.7.65
ip route add (network)/(mask) src INTERFACE_IP dev (device)
ip route add (network)/(mask) dev (device) protocol static

Add Static Route (old "route" method)
route add -net 10.0.0.0 netmask 255.255.255.0 dev eth0

Add Default Route
ip route add default via GATEWAY_IP

Add Default Route (old "route" method)
route add default gw 192.168.1.1

Del Route
ip route del 10.0.0.0/24

Delete all routes on an interface
ip route flush dev eth0


http://www.policyrouting.org/iproute2.doc.html
http://gentoo-wiki.com/Dual_internet_connections

Saturday, April 07, 2007

Date Time Clocks

Setting the timezone:
ln -sf /usr/share/zoneinfo/your/zone /etc/localtime

Setting the timezone for a particular user:
export TZ=America/Chicago

Show time in a given timezone:
# relative to the /usr/share/zoneinfo/ directory
zdump Japan
zdump America/Chicago
zdump US/Central

# absolute path to zonefile
zdump /etc/localtime
zdump /usr/share/zoneinfo/America/Chicago

View date and time:
date
date --utc #universal time

Set the date and time:
date -s "16:15:00" # just the time
date -s "16:15:00 April 7, 2007" # date and time
date 040716552007.00 # the fields being MMDDhhmmCCYY.ss

Verify connectivity with NTP server:
ntpdate -q time.nist.gov

Several common time servers:
clock.redhat.com
clock2.redhat.com
ns1.tuxfamily.org
time.nist.gov
time.apple.com

Manually use NTP to set time:
ntpdate time.nist.gov
ntpdate -v time.nist.gov # verbose output

Use NTPd to automatically set date and time:
/etc/init.d/ntpd start #ntpd must be installed, of course

Monitor NTPd:
ntpdc -p
ntpdc -p -n


http://www.linuxsa.org.au/tips/time.html
http://www.vanemery.com/Linux/RH-Linux-Time.html

Sunday, April 01, 2007

Fake RAID links

Wikipedia FakeRAID Def
http://en.wikipedia.org/wiki/Fakeraid
Not transparent to the OS like real RAID. Not controlled entirely by the operating system either like softRAID. However, it uses hardware and needs an OS driver.

LINUX FakeRAID drivers
http://linux-ata.org/driver-status.html

List of FaikRAID hardware devices/controllers
http://linuxmafia.com/faq/Hardware/sata.html

My MoBo
http://www.pcstats.com/articleview.cfm?articleid=1770&page=1

This Mobo uses the following kernel modules:
sata_nv: for the 4 nForce4 controllers

kernel configure option:
CONFIG_SATA_NV=y


menconfig path:
- Device Drivers -->
-- Serial ATA (prod) and ... -->
--- ATA device support -->
---- NVIDIA SATA support
----- sata_sil: for the 4 Sillicon Image 3314 controllers


kernel configure option:
CONFIG_SATA_SLI = y

menuconfig path:
- Device Drivers -->
-- Serial ATA (prod) and ... -->
--- ATA device support -->
---- Silicon Image SATA support
----- ahci: generic Open standard (I don't have this, but worth a mention)


kernel configure option:
CONFIG_SATA_AHCI=y

menuconfig path:
- Device Drivers -->
-- Serial ATA (prod) and ... -->
--- ATA device support -->
---- AHCI SATA support


Both of these modules depend on the module:
libata

Libata depends on the following module:
scsi_mod

kernel configure option:
CONFIG_SCSI=y

menuconfig path:
- Device Drivers -->
-- SCSI device support -->
--- SCSI device support

Tuesday, March 20, 2007

Linux Quota Support

http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html

mdadm software raid usage

Install
mdadm package needed (aptitude install mdadm)

http://neil.brown.name/blog/mdadm


Create array:

mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1
or
mdadm -Cv /dev/md0 -l0 -n2 -c128 /dev/sdb1 /dev/sdc1

/etc/mdadm.conf

# optional, but used for easier interaction
DEVICE /dev/sdb1 /dev/sdc1
ARRAY /dev/md0 devices=/dev/sda1,/dev/sdb1

Show md info:
# produces output that you would put in the mdadm.conf

mdadm --detail --scan

Show device info:
mdadm -E /dev/sdc1
# shows info about the component disks

Start (assemble) Existing Array:
mdadm -As /dev/md0
# -A starts assemble mode to assemble existing array
# -s indicates the use of /etc/mdadm.conf
or
mdadm -A /dev/md0 /dev/sdb1 /dev/sdc1
# starts array without existing /etc/mdadm.conf

Assemble an existing array automatically:
mdadm --assemble --scan
or
mdadm -As

Stop the array:
mdadm -S /dev/md0
or
mdadm --stop /dev/md0

Add a disk:
mdadm /dev/md0 --add /dev/sdc1

Remove a disk:
mdadm /dev/md0 --fail /dev/sdc1 --remove /dev/sdc1
# "fails" and removes a disk

fstab entry for the array:
# this assumes the array was formated with ext3
/dev/md0 /export/ ext3 suid,dev,defaults,exec 0 0


http://www.linuxdevcenter.com/pub/a/linux/2002/12/05/RAID.html

Saturday, March 03, 2007

SUDO

Generic syntax of /etc/sudoers
<users_to_allow> <host> = (run_as_user) <command_to_run>
<users_to_allow> <host> = (run_as_user) <file_to_grant>

No password for users in admin group

%admin ALL= (ALL) NOPASSWD: ALL

No password for joeuser user
joeuser ALL=(ALL) NOPASSWD: ALL

Allow joeuser to run only certain privileged commands as root
joeuser ALL= /bin/kill, /usr/local/bin/

Allow joeuser to run certain commands as given users
joeuser ALL=(janeuser,johnuser) /bin/kill, /usr/local/bin

Run sudo command as another user using
sudo -u janeuser /bin/kill

http://aplawrence.com/Basics/sudo.html

Monday, February 26, 2007

Screen Command Usage

Create a new Screen session
screen # creates a default session
screen -S name # creates a session with a name

# Screen has two similar concepts: screens and window sessions.
# screens are seperate processes that show up when doing
# a "screen -ls" listing. Windows are "sub-screens" of a given
# screen process used for split screen modes and such.

Rename an already created window
CTRL-a A # then provide name

Rename a screen (interactively)
CTRL-a :sessionname newsessionname

Rename a screen (without attaching)
screen -X sessionname newsessionname

Detach from a screen session
screen -d # detach from a command prompt
Ctrl-a d # detach from anywhere in the session

List screen sessions

screen -ls

Reattach to a screen session
screen -r # attaches to default session
screen -r name # attaches to specific session (unique string in the name)


Toggle between several attached windows
Ctrl-a Ctrl-a

Attach to an already attached screen (mirror)
screen -x # attaches to default session
screen -x name # attaches to named session

Share a screen session

owner:
screen -S name # start and name the screen
Ctrl-a :multiuser on # add multiuser support
Ctrl-a :acladd userids # share the screen to userids (comma sep)

client:
screen -x username/session # attach to the screen (in mirror)


Change permissions on a shared session
owner:
Ctrl-a :aclchg userids [permbits] [list]
# permbits = rwx and prefixed by "-" or "+"
# list of commands - #(all windows), ?(all commands)

Remove user access
owner:
acldel userids


Lock a Screen
ctrl-a ctrl-x # requires user to enter password to unlock

Copy and Paste from the screen scrollback buffer
Ctrl-a [Esc] # enters scrollback editor (movement like vi)
[spacebar] # starts and stops a copy selection range
Ctrl-a :paste . # pastes the copy buffer to the term


Screenrc options:
/home/> vi .screenrc
#shell -bash
shell -ksh # Make Screenrc exe .profile file on login


# Set the scrollback buffer
defscrollback 5000

# Turn off the startup banner
startup_message off

# displays a status line at the bottom of the terminal window.
hardstatus alwayslastline "Screen: %w %c:%s %D, %M/%d/%Y "

# detach on hangup - if my dial-up session fails, screen will simply
# detach and let me re re-attach later
autodetach on

Split Screen
# Create two screens
screen # create first screen
CTRL-a c # create second screen session (1 screen instance, but 2 window sessions)
CTRL-a S # split the screen
CTRL-a TAB # move to the bottom part of the split
CTRL-a " # will prompt for a screen number. Choose 0 or 1 indicating the window session
CTRL-a Q # quit all splits except the current

Scrollback / Copy and Paste
CTRL-a [ or CTRL-a ESC # frees the cursor to move into scrollback buffer (Copy mode)
# ESC to exit copy mode without copying
# use arrow keys or h,j,k,l to navigate in copy mode
# use CTRL-F and CTRL-B to page up and down in copy mode

ENTER # indicates a start point for text copy
ENTER # (second) indicates an end point for text copy
CTRL-a ] # pastes copied text range

http://aperiodic.net/screen/quick_reference
http://news.softpedia.com/news/GNU-Screen-Tutorial-44274.shtml

Tuesday, February 20, 2007

SSH Port Forward

Allow port forwarding on the server
# Edit the /etc/ssh/sshd_config
AllowTcpForwarding yes

Local Forward

# create a tunnel to access an ssh server behind a firewall using a gateway
ssh -L 7777:192.168.1.160:22 gateway.example.com cat -

# access the ssh server via your local machine
ssh -p 7777 localhost

http://www.securityfocus.com/infocus/1816

Tuesday, February 13, 2007

Find File Space Usage

Find space used on filesystem level:
du -ks # shows summary of space used on disk in Kb
du -ms # shows summary of space used on disk in Mb
du -gs # show summary of space used on disk in Gb

Find space used on a file level:
find . -type f -ls | awk '{print $7}' | while read size
do
((TSIZE=TSIZE + $size))
done
echo "$TSIZE"

Shows largest files in a directory:
ls -l | sort -k 5rn,5 -k 9fd,9
-k = search criteria
5 = sort column five
r = apply reverse sort
n = numeric sort

Shows files using the most space on the filesystem:
du -ak | sort -k 1rn -k 2fd

Shows users using the most space:
# this space list will not include files or dirs that the current
# user has no read permissions on
ls /home/ | while read a
do
du -sm /home/$a
done 2> /dev/null | sort -k 1n | tail -10



http://www.devdaily.com/unix/edu/examples/sort.shtml
http://www.cs.rit.edu/~vcss231/Labs/Tips/unix-w8.html

Friday, January 12, 2007

OpenLDAP Commands

Search ldap database:
view everything anonymously authenticated
ldapsearch -x -b 'dc=example,dc=com'
-x : unauthenticated
-b : baseDN
-h : host
-p : port (389 normal; 636 secure)

Same as above but more explicit
ldapsearch -x -b 'dc=example,dc=com' '(objectclass=*)'

The test in the parens can be used to restrict the search and return only records for which that test is true. For example, the following will only return the record whose uid is set to joeuser.
ldapsearch -x -b 'dc=example,dc=com' '(uid=joeuser)'

Sunday, January 07, 2007

dm-crypt filesystem encryption

Dependencies needed:
Kernel Setup:
Device Drivers > Multi-device support (RAID and LVM) > Device Mapper Support (dm-mod)
Device Drivers > Multi-device support (RAID and LVM) > Crypt Target Support (dm-crypt)
Cryptographic Options > (Select cyphers .. ex. aes, twofish)


Userspace tools needed:
cryptsetup.sh
libdevmapper

cryptsetup.sh Syntax:
Syntax: cryptsetup [<OPTIONS>] <action> <name> [<device>]
<OPTIONS>:
-c <cipher> (see /proc/crypto)
-h {plain/<hash>} (see hashalot)
-y (verifies the passphrase by asking for it twice)
-d <file> (read key from file
e.g. /dev/urandom; useful for swap devices.
If set, the parameters -h and -y will be ignored)
-s <keysize> (in bits) (WARNING: in bytes for cryptsetup.sh)
-b <size> (in sectors)
-o <offset> (in sectors)
-p <skipped> (in sectors)
<action> is one of:
create - create device
remove - remove device
reload - modify active device
resize - resize active device
status - show device status
<name> is the device to create under /dev/mapper/
<device> is the encrypted device

Create crypto physical device (sized by existing partition):
cryptsetup.sh -c aes -h plain -y -b `blockdev --getsize \
/dev/hdb2` create cryptvol1 /dev/hdb2

Copy over data:
dd if=/dev/hdb2 of=/dev/mapper/cryptvol1 bs=4k

http://www.linux.com/article.pl?sid=04/06/07/2036205
http://www.saout.de/misc/dm-crypt/

Saturday, January 06, 2007

rsync

Syntax:
rsync -vaHx --progress --numeric-ids --delete \
--exclude-from=asylum_backup.excludes --delete-excluded \
username@host:/home/userdir/ /backupdir/
Common options:
-v: verbose
-r: recursive
-a: archive - maintain perms, ownership
-H: Maintain hard links
-x: no recursion into other filesystems
--progress: shows progress info
--numeric-ids: don't translate UID/GIDs; important for backups.
--delete: delete from backup files that no longer exist on server
--exclude-from=file.txt: specifies a file to exclude paths. One path per line.
--delete-excluded: delete files previous backup which are now within exclude list
username@: username on remote host
host:: name of host
/home/userdir: path to backup
    trailing slash: backup contents of dir
no trailing slash: backup dir
/backupdir: location to backup files

Example of simple copy:
rsync -r -e ssh --delete /home/user/ user@host:/backups/


http://www.sanitarium.net/golug/rsync_backups.html
http://linuxgazette.net/104/odonovan.html