MySQL Password Recovery

1. Stop mysql
# /etc/init.d/mysql stop

2. Start mysql without password:
# mysqld_safe –skip-grant-tables &

3. Connect to mysql server
# mysql -u root

4. Update root password
mysql> use mysql;
mysql> update user set password=PASSWORD(“new_password”) where User=’root’;
mysql> flush privileges;
mysql> quit

5. Restart mysql
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

6. Connect mysql using new password
# mysql -u root -p

JDK, SDK, JRE, J2SE, J2ME, J2EE

JDK (Java Development Kit)
For developing or compiling Java programs (*.java -> *.class -> *.jar)

SDK (Software Development Kit)
a common term

JRE (Java Runtime Environment)
For executing a Java program

J2SE (Java 2 Standard Edition)
For common purposes. e.g. on PC

J2ME (Java 2 Micro Edition)
For small devices. e.g. mobile phones, palmtops

J2EE (Java 2 Enterprise Edition)
AFAIK framework and methodology to produce applications in 3-layer technology (robust applications)

Password Recovery

Steps:

In GRUB selection screen, press ‘e’ to edit the first line
Debian GNU/Linux, kernel 2.4.27-2-386

press ‘e’ to edit the second line
BEFORE: kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro
AFTER : kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro init=/bin/bash

press ‘b’ to boot
mount -no remount,rw /
passwd root
reboot

FTP Server

Introduction
use linux account to login
access user’s home directory (e.g. /home/alan)

Install Proftpd
aptitude install proftpd

Stop Proftpd
/etc/init.d/proftpd stop (start / reload / restart)

Configure deny list
vim /etc/ftpusers
/etc/init.d/proftpd reload

Install FTP client
aptitude intsall ftp

Display number of users
ftpcount

Display user list
ftpwho

Download files without prompt
ftp -i 192.168.1.1
mget *

Cron Job

Edit crontab
crontab -e
mm hh dd MM WK COMMAND (eg. * * 7 1 * uptime >> /var/log/uptime.log)

List all cron jobs
crontab -l

Remove crontab
crontab -r

Install crontab from file
crontab ~/mycron.txt (install)

Manage crontab of other user
crontab -u alan -e
crontab -u alan -l
crontab -u alan -r
crontab -u alan ~/mycron.txt

Control who can access crontab
vim /etc/cron.deny
vim /etc/cron.allow
(Enter username)

Compression

Compression Method
gzip  (1K corrupted will cause whole file crashed)
bzip2 (better; 1K corruped only cause 900K crashed)

bzip2 (.bz2)
Install
aptitude intsall bzip2

Compress
bzip2 /xxx
bzip2 -k /xxx (k: keep the old file)

Decompress
bzip2 -d /xxx.bz2
bzip2 -dk /xxx.bz2 (k: keep the old file)

gzip (.gz)
Install
aptitude intsall gzip

Compress
gzip /xxx

Decompress
gzip -d /xxx

tar (.tar .tar.bz2)
Compress
tar -cf /xxx.tar /xxx
tar -cjf /xxx.tar.bz2 /xxx
tar -czf /xxx.tar.gz /xxx

Decompress
tar -xf /xxx.tar
tar -xjf /xxx.tar.bz2
tar -xzf /xxx.tar.gz

Install
aptitude intsall bzip2

Apache

Install
aptitude install apache2
(home folder: /var/www/apache2-default/)

Edit port
vim /etc/apache2/ports.conf
/etc/init.d/apache2 reload

Change home directory
vim /etc/apache2/sites-enabled/000-default
# RedirectMatch ^/$ /apache2-default/
(redirect = edit the url)
/etc/init.d/apache2 reload

Add virtual directory
vim /etc/apache2/sites-enabled/000-default
Alias /virtual/ /var/www/real
<Directory “/var/www/real”>
</Directory>
/etc/init.d/apache2 reload

Add virtual host
vim /etc/apache2/sites-available/cse
NameVirtualHost *
<VirtualHost *>
ServerName cse.ust.com
DocumentRoot /cse/
</VirutalHost>
vim /etc/apache2/sites-available/cpeg
<VirtualHost *>
ServerName cpeg.ust.com
DocumentRoot /cpeg/
</VirutalHost>
a2ensite cse
a2ensite cpeg
/etc/init.d/apache2 reload

Enable userdir
a2enmod userdir
mkdir /home/alan/public_html
chmod 755 /home/alan/public_html
http://127.0.0.1/~alan

. Install
– aptitude install apache2
– (home folder: /var/www/apache2-default/)
. Edit port
– edit /etc/apache2/ports.conf
– /etc/init.d/apache2 reload
. Change home directory
– edit /etc/apache2/sites-enabled/000-default
# RedirectMatch ^/$ /apache2-default/
(redirect = edit the url)
– /etc/init.d/apache2 reload
. Add virtual directory
– edit /etc/apache2/sites-enabled/000-default
Alias /virtual/ /var/www/real
<Directory “/var/www/real”>
</Directory>
– /etc/init.d/apache2 reload
. Add virtual host
– vim /etc/apache2/sites-available/cse
NameVirtualHost *
<VirtualHost *>
ServerName cse.ust.com
DocumentRoot /cse/
</VirutalHost>
– vim /etc/apache2/sites-available/cpeg
<VirtualHost *>
ServerName cpeg.ust.com
DocumentRoot /cpeg/
</VirutalHost>
– a2ensite cse
– a2ensite cpeg
– /etc/init.d/apache2 reload
. Enable userdir
– a2enmod userdir
– mkdir /home/alan/public_html
– chmod 755 /home/alan/public_html
– http://127.0.0.1/~alan

sudo

Introduction
allows normal users to run command as root

Install sudo
apt-get install sudo

Configuration
Edit /etc/sudoers and enter these 2 lines:
uname    host=(runas) cmd
alan     pc1,pc2=(root,daemon) /bin/ls,/bin/cp,/usr/bin/whoami

Using sudo
sudo whoami
sudo -u david whoami

Get full sessions as root
sudo su –

Logging
/var/log/auth.log

User Accounts Management

Create User Account
adduser USERNAME

Delete User Account
deluser USERNAME

Additional Options:
apt-get install perl-modules
deluser –remove-all-files USERNAME
deluser –backup USERNAME
deluser –remove-all-files –backup USERNAME

Create Group
addgroup GROUPNAME

Delete Group
delgroup GROUPNAME
delgroup –only-if-empty GROUPNAME

Add user to a group
adduser USERNAME GROUPNAME

Remove user from a group
deluser USERNAME GROUPNAME

Lock User Account
passwd -l USERNAME

Unlock User Account
passwd -u USERNAME

List Age
chage -l USERNAME

Change Age
chage -E 2007/09/01 USERNAME

Print UID, GID
id USERNAME