Acknowledgement

This is a note that I sit in the Practical Workshop class with MSIT121)

Lecturer: Assistant Prof. Dr. Arnon Rungsawang

Well, I have already test and review the content below. Any problems you have, please report direct to me @klainfo

Setup Network

  1. Setup
    $ setup
  2. Click Network Configuration → Yes → (Enable) Use Dynamic IP Configuration(BOOTD/DHCP) → OK → Quit
  3. start service
    $ service network start
  4. look for ip and test it
    $ ifconfig eth0
    $ nslookup www.ku.ac.th

Update Repo

$ cd /etc/yum.repos.d
$ mv CentOS-Base.repo CentOS-Base.repo.save
$ wget http://mirror1.ku.ac.th/yum-centos/4/CentOS-Base.repo
$ yum update  หรือ yum -y update

Group and User

  1. Add Group
    $ groupadd -g 500 staff
  2. Delete Group
    $ groupdel %groupname
  3. Add User
    $ useradd -g staff -md /home/klainfo klainfo
    $ passwd klainfo
  4. Change user's home directory
    $ usermod -d /home/%newdir -m %username
    
  5. Change login name
    $ usermod -l %new %old
    
  6. Change group
    $ usermod -g %group %username
    
  7. Change password policy
    $ chage
    
  8. Delete user
    $ userdel %username
    $ userdel -r %username # delete user and home directory
    

ไฟล์ที่สำคัญ

  1. /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    # LoginName:x:UserID:GroupID:UesrInfo:HomeDir:DefaultShell
  2. /etc/group
    root:x:0:
    # GroupName:x:GroupID:UserList
    # Example
    staff:x:1000:klainfo,pamon

Quota Management

  1. ดู target file system ที่ต้องการจะกำหนด Quota (เช่น /dev/hda?) (e.g. /home)
    $ df
    
  2. เปิดการใช้งาน User กับ Group Quota
    $ vi /etc/fstab
    
    1. Change “LABEL=/home” → ”/dev/hda?”
    2. Edit like this “default,usrquota,grpquota”
    3. Save
  3. Remounting the file system
    $ umount /home; mount /home;
  4. Create User and Group quota list. You can see aquota.user and aquota.group automatically at /home
    $ quotacheck -aug
  5. List aquota.user and aquota.group
    $ repquota -aug
    1. -a : list all
    2. -u : list user
    3. -g : list group
  6. Set User Quota
    $ setquota -u %username %softlimit %hardlimit 0 0 %targetfs
    เช่น
    $ setquota -u kla 50000 70000 0 0 /home
    
    $ edquota -u %username
    1. Disk quotas for user kla (uid 500):
       Filesystem     blocks       soft       hard     inodes     soft     hard
       /dev/sda3      8               0          0          4        0        0
      
    2. blocks คือ พื้นที่(ขนาดไฟล์) ที่ใช้ไป (1 block = 1K bytes)
    3. soft คือ Soft Limit เป็น quota ขั้นต่ำ อนุญาตให้ user ใช้พื้นที่เกิน quota นี้ได้ แต่ไม่เกิน grace วัน ถ้าใส่ 0 คือไม่กำหนด
    4. hard คือ Hard Limit เป็น quota สูงสุด (เกิน soft ได้ แต่ห้ามเกิน hard)
    5. inodes คือ จำนวนไฟล์ ที่ใช้ไป โดยมี soft และ hard เช่นเดียวกับ blocks
    6. grace คือ จำนวนวันที่สามารถใช้พื้นที่เกิน soft limit ได้
  7. Set Group Quota
    $ setquota -g %groupname %softlimit %hardlimit 0 0 %targetfs
    เช่น
    $ setquota -g staff 50000000 70000000 0 0 /home
    
    $ edquota -g %groupname
  8. เปิดการใช้งาน User and Group Quota
    $ quotaon -avugfp หรือ
    # quotaon -a
  9. วิธีเขียนไฟล์บน harddisk (ทดสอบว่า limit quota สำเร็จหรือไม่ โดยการสร้างไฟล์ขนาดใหญ่ๆ)
    $ dd if=/dev/zero of=%filename bs=1024 count=%amount
    เช่น
    bs = 1024 bytes, count = 1000, It's 1MBytes.
    $ dd if=/dev/zero of=/home/klainfo/test bs=1024 count=1000
    

Run Level [No reviewed]

ตรวจสอบ

$ runlevel

  1. Lv 0 คือการสั่งปิดเครื่อง
  2. Lv 1 เป็นการทำงานแบบ Single user mode คือ root สามารถใช้งานได้คนเดียว
  3. Lv 2 User อื่นสามารถใช้งานได้ แต่จะไม่สามารถใช้งานผ่าน Network ได้ ( ต้อง Login โดยตรงจากเครื่อง )
  4. Lv 3 Full Multi user mode ผู้ใช้งานคนอื่นๆสามารถใช้งานได้ และสามารถ login ผ่าน network ได้แต่ไม่มี X-Windows
  5. Lv 4 ???
  6. Lv 5 Full Multi user node ใน Level นี้จะเรียกใช้งาน X-Windows ด้วย
  7. Lv 6 restart เครื่อง

เปลี่ยนไปที่ Level 3

$ init 3

System Log

  1. /var/log/dmesg : kernel message
  2. /var/log/messages : general message
  3. /var/log/secure : log in and security information

Cron Job

Create or edit your crontab file

$ crontab -e

Display your crontab

$ crontab -l

Remove your crontab

$ crontab -r

Crontab file

min hour day of month(1-31) month day of week(0-6) command comment
* * * * * %command # run ทุกๆ 1 วินาที
30 0 1 1,6,12 * %command # run ทุกๆ 00:30 Hr on 1st of Jan, June & Dec
0 20 * 10 1-5 %command # run ทุกๆ 8:00PM every weekday(Mon-Fri) only in Oct.
0 0 1,10,15 * * %command # run midnight on 1st, 10th & 15th of month
5,10 0 10 * 1 %command # run at 12:05 and 12:10 every Monday and 10th of every month

Sudo Configuration(visudo)

$ visudo
--------------
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification
Host_Alias MASTER = localhost

# User alias specification
User_Alias ADMINS = kla

# Cmnd alias specification
Cmnd_Alias POWER = /sbin/poweroff
Cmnd_Alias IPTABLES = /sbin/iptables -L

# Defaults specification

# User privilege specification
root    ALL=(ALL) ALL
staff   ALL=(ALL) ALL

# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

# Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now
kla localhost=IPTABLES

  1. การตั้ง Alias จะใช้ได้เฉพาะ ใน visudo file
  2. Host_Alias MASTER = localhost หมายถึง จะเรียก localhost ว่า MASTER แทน
  3. Cmnd_Alias POWER = /sbin/poweroff หมายถึง จะเรียกคำสั่ง ”/sbin/poweroff” ว่า POWER แทน
  4. # User privilege specification การกำหนดสิทธิของ Group ให้ run command บางส่วน
    1. root ALL=(ALL) ALL หมายถึง ให้ group root สามารถทำได้ทุกอย่าง
    2. staff ALL=(ALL) ALL หมายถึง ให้ group staff สามารถทำได้ทุกอย่าง
    3. staff localhost=(ALL) ALL หมายถึง ให้ group staff สามารถทำ ได้เฉพาะบนเครื่องเท่านั้น หมายถึง ห้าม ssh เข้ามาสั่ง
  5. kla localhost=IPTABLES,POWER หมายถึง ให้ user “kla” สามารถ run ”/sbin/iptables -L” และ ”/sbin/poweroff” ได้เฉพาะบนเครื่องเท่านั้น หมายถึง ห้าม ssh เข้ามาสั่ง

Permit Root Login

Open file

$ vi /etc/ssh/sshd_config

Uncommented

PermitRootLogin yes

Restart service

$ service sshd restart

Related Content

1) Master of Science Program in Information Technology
 
centos_basic.txt · Last modified: 2010/02/02 01:25 (external edit) · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki