Kamis, 21 Januari 2010
Merubah tanggal system di linux
* cek tanggal sekarang
# date
Tue Sep 7 11:48:37 EDT 2009
* Ganti tanggal menjadi 8 September 2009
# date +%Y%m%d -s 20090908
20090908
hasilnya jika di cek yaitu : Tue Sep 8 00:00:02 EDT 2009
ternyata jamnya menjadi 00
* Ganti jam menjadi 11:50:00
# date +%T -s 11:50:00
11:50:00
hasilnya jika di cek yaitu : Tue Sep 8 11:50:10 EDT 2009
jam dan tanggal sudah benar, akan tetapi timezone mash salah
default masih EDT
* Ganti time zone ke WIB atau bahasa inggrisnya WIT (West Indonesian Time)
1. Data zone disimpan di file /etc/localtime
2. Data zona selengkapnya disimpan di /usr/share/zoneinfo/nama kota, sehingga kalai untuk Jakarta filenya yaitu /usr/share/zoneinfo/Asia/Jakarta
3. ganti file /etc/localtime agar sama dengan file di point ke 2
# mv /etc/localtime /etc/localtime.old
# ln -s /usr/share/zoneinfo/Asia/Jakarta /etc/localtime
hasilnya jika di cek yaitu : Tue Sep 8 23:52:40 WIT 2009
ternyata hasil jamnya malah salah, jadi disesuaikan lagi
# date +%T -s 11:52:00
hasilnya jika dicek yaitu : Tue Sep 8 11:52:02 WIT 2009
* sesuaikan jam system linuk dengan jam komputer (Hardware)
1. system akan melakukan penyesuaian dengan jam komputer saat startup
2. untuk melihat jam komputer dengan perintah “hwclock”
3. untuk merubah jam komputer agar sesuai dengan sistem dengan perintah “hwclock –systohc”
# hwclock
Tue 07 Sep 2009 12:25:27 PM WIT -0.126089 seconds
# hwclock –systohc
cek hasilnya :
# hwclock
Tue 08 Sep 2009 12:25:27 PM WIT -0.126089 seconds
# date
Tue Sep 8 12:25:28 WIT 2009
Install ARJ di Linux Centos
extract file arj :
# tar zxvf arj-3.10.22.tar.gz
masuk kedalam dir extrakan arj
[root@tester src]#cd arj-3.10.22/gnu
[root@tester gnu]# autoconf
[root@tester gnu]# ./configure
setelah selesai kembali ke direktori arj
# cd ..
lakukan make prepare
[root@tester arj-3.10.22]# make prepare
[root@tester arj-3.10.22]# make
[root@tester arj-3.10.22]# make install
Kamis, 07 Januari 2010
10 UNIX Command Line Mistakes
10 UNIX Command Line Mistakes
Anyone who has never made a mistake has never tried anything new. -- Albert Einstein.
Here are a few mistakes that I made while working at UNIX prompt. Some mistakes caused me a good amount of downtime. Most of these mistakes are from my early days as a UNIX admin.
userdel Command
The file /etc/deluser.conf was configured to remove the home directory (it was done by previous sys admin and it was my first day at work) and mail spool of the user to be removed. I just wanted to remove the user account and I end up deleting everything (note -r was activated via deluser.conf):userdel foo
Rebooted Solaris Box
On Linux killall command kill processes by name (killall httpd). On Solaris it kill all active processes. As root I killed all process, this was our main Oracle db box:killall process-name
Destroyed named.conf
I wanted to append a new zone to /var/named/chroot/etc/named.conf file., but end up running:./mkzone example.com > /var/named/chroot/etc/named.conf
Destroyed Working Backups with Tar and Rsync (personal backups)
I had only one backup copy of my QT project and I just wanted to get a directory called functions. I end up deleting entire backup (note -c switch instead of -x):cd /mnt/bacupusbharddisk
tar -zcvf project.tar.gz functions
I had no backup. Similarly I end up running rsync command and deleted all new files by overwriting files from backup set (now I’ve switched to rsnapshot)rsync -av -delete /dest /src
Again, I had no backup.
Deleted Apache DocumentRoot
I had sym links for my web server docroot (/home/httpd/http was symlinked to /www). I forgot about symlink issue. To save disk space, I ran rm -rf on http directory. Luckily, I had full working backup set.
Accidentally Changed Hostname and Triggered False Alarm
Accidentally changed the current hostname (I wanted to see current hostname settings) for one of our cluster node. Within minutes I received an alert message on both mobile and email.hostname foo.example.com
Public Network Interface Shutdown
I wanted to shutdown VPN interface eth0, but ended up shutting down eth1 while I was logged in via SSH:ifconfig eth1 down
Firewall Lockdown
I made changes to sshd_config and changed the ssh port number from 22 to 1022, but failed to update firewall rules. After a quick kernel upgrade, I had rebooted the box. I had to call remote data center tech to reset firewall settings. (now I use firewall reset script to avoid lockdowns).
Typing UNIX Commands on Wrong Box
I wanted to shutdown my local Fedora desktop system, but I issued halt on remote server (I was logged into remote box via SSH):halt
service httpd stop
Wrong CNAME DNS Entry
Created a wrong DNS CNAME entry in example.com zone file. The end result - a few visitors went to /dev/null:echo 'foo 86400 IN CNAME lb0.example.com' >> example.com && rndc reload
Failed To Update Postfix RBL Configuration
In 2006 ORDB went out of operation. But, I failed to update my Postfix RBL settings. One day ORDB was re-activated and it was returning every IP address queried as being on its blacklist. The end result was a disaster.
Conclusion
All men make mistakes, but only wise men learn from their mistakes -- Winston Churchill.
From all those mistakes I’ve learnt that:
- Backup = ( Full + Removable tapes (or media) + Offline + Offsite + Tested )
- The clear choice for preserving all data of UNIX file systems is dump, which is only tool that guaranties recovery under all conditions. (see Torture-testing Backup and Archive Programs paper).
- Never use rsync with single backup directory. Create a snapshots using rsync or rsnapshots.
- Use CVS to store configuration files.
- Wait and read command line again before hitting the dam [Enter] key.
- Use your well tested perl / shell scripts and open source configuration management software such as puppet, Cfengine or Chef to configure all servers. This also applies to day today jobs such as creating the users and so on.
Referensi from www.cyberciti.biz
How to Compile Linux kernel 2.6
How to: Compile Linux kernel 2.6
Compiling custom kernel has its own advantages and disadvantages. However, new Linux user / admin find it difficult to compile Linux kernel. Compiling kernel needs to understand few things and then just type couple of commands. This step by step howto covers compiling Linux kernel version 2.6.xx under Debian GNU Linux. However, instructions remains the same for any other distribution except for apt-get command.
Step # 1 Get Latest Linux kernel code
Visit http://kernel.org/ and download the latest source code. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number. For example file inux-2.6.25.tar.bz2 represents 2.6.25 kernel version. Use wget command to download kernel source code:$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2
Note: Replace x.y.z with actual version number.
Step # 2 Extract tar (.tar.bz3) file
Type the following command:# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
# cd /usr/src
Step # 3 Configure kernel
Before you configure kernel make sure you have development tools (gcc compilers and related tools) are installed on your system. If gcc compiler and tools are not installed then use apt-get command under Debian Linux to install development tools.# apt-get install gcc
Now you can start kernel configuration by typing any one of the command:
- $ make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
- $ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
- $ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.
For example make menuconfig command launches following screen:$ make menuconfig
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.
Step # 4 Compile kernel
Start compiling to create a compressed kernel image, enter:$ make
Start compiling to kernel modules:$ make modules
Install kernel modules (become a root user, use su command):$ su -
# make modules_install
Step # 5 Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.# make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:
- System.map-2.6.25
- config-2.6.25
- vmlinuz-2.6.25
Step # 6: Create an initrd image
Type the following command at a shell prompt:# cd /boot
# mkinitrd -o initrd.img-2.6.25 2.6.25
initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.
Step # 7 Modify Grub configuration file - /boot/grub/menu.lst
Open file using vi:# vi /boot/grub/menu.lst
title Debian GNU/Linux, kernel 2.6.25 Default
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hdb1 ro
initrd /boot/initrd.img-2.6.25
savedefault
boot
Remember to setup correct root=/dev/hdXX device. Save and close the file. If you think editing and writing all lines by hand is too much for you, try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type the command:# update-grub
Neat. Huh?
Step # 8 : Reboot computer and boot into your new kernel
Just issue reboot command:# reboot
referensi from www.cyberciti.biz
Rabu, 23 Desember 2009
USER & GROUP DI LINUX
MENGOLAH USER DAN GROUP DI LINUX
Dalam sistem berbasis Linux memiliki username-username spesial untuk kepenrtingan fungsi-fungsi sistem. Username ini memiliki UID sebagaimana username yang diasosiasikan untuk user-user. Berikut ini user-user umum yang dimiliki oleh default sistem UNIX/Linux :
- root, yakni superuser yang membentuk account dan mengendalikan fungsi-fungsi sistem.
- daemon atau sys, yang menangani aspek-aspek jaringan. Username ini diasosiasikan juga utilitas sistem lain, seperti print spooler dalam beberapa versi tertentu.
- agent, yang menangani aspek mail elektronik, pada beberapa sistem, agent memiliki UID yang sama dengan daemon.
- guest, digunakan bagi para pengunjung untuk mengakses sistem.
- ftp, digunakan untuk akses anonymous FTP.
- uucp, untuk mengatur uucp sistem.
- news, digunakan untuk Usenet news
- lp, digunakan untuk line printer system.
- nobody, yakni user yang tidak memiliki file-file. Terkadang digunakan sebagai default user untuk operasi-operasi kurang openting.
User Identitas (UID)
UID secara historis dibentuk oleh integer-integer 16 bit, yang berarti mereka dapat melakukan range dari 0 hingga 65535. UID 0 dan 9 secara typical digunakan untuk fungsi-fungsi system. UID untuk orang-orang biasanya dimulai dari 20 atau 100. Linux menyimpan mappong antar-username dan UID-UID dalam file /etc/passwd. Masing-masing UID user diletakkan dalam field setelah password-password yang terenkripsi.
Perhatikan contoh isi dari satu record /etc/passwd :
Test:eH5/.mj7NHB3dx:181:100:Test:/home/Test:/bin/ksh
Dari contoh diatas, user anjik dengan UID 181. UID tidak lain adalah informasi aktual yang digunakan sistem operasi untuk mengidentifikasi user-user. Seandainya dua atau beberapa user memiliki UID yang sama, meski mereka memiliki username berbeda dan password berbeda pula. User dengan UID yang sama dapat secara bebas membaca file-file, melakukan penghapusan, mengeksekusi program, mengkill proses-proses yang berjalan.
Linux menyediakan utilitas useradd untuk menambahkan nama pemakai baru ke sistem.
Usage : useradd [-u uid] [-o]] [-g group] [-G group,…]
[-d home] [-s shell] [-c comment] [-m [-k template]]
[-f inactive] [-e expire ] [-p passwd] [-n] [-r] name
useradd –D [-g group] [-b base] [-s shell]
[-f inactive] [-e expire]
-u user-id
-g group-id
-G secondary group
-d direktori awal (HOME), bila tidak diberikan, maka sebagai default
diambil nama pemakai tsb dan ditambahkan ke direktori default
(misalnya /home)
-s shell, /bin/bash dan lainnya
-c comment, info atau keterangan tentang pemakai tersebut
-m direktori HOME akan diciptakan, bila belum ada. Files yang berada
pada direktori /etc/skel akan dicopy untuk menjadi default profile
pemakai tersebut.
-k bersama dengan –m, memberikan nama kerangka (skelet) direktori
yang berbeda dengan skel
-f inactive_days, jumlah hari sebelum account tersebut dibekukan, bila masa
berlaku password telah berakhir.
-e tanggal habis berlaku nama login tersebut
-p encrypted password
Membuat user sederhana :
# useradd test
Membuat user, dengan menyertakan semua parameter dari nilai default, yang dapat dilihat dengan menggunakan option –D:
#useradd –D
GROUP=100
HOME=/home
INACTIVE=1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
Melihat HOME directory serta file inisialisasi:
# ls –1 /home
total 17
drwx------ 4 test 1024 Nov 27 13:50 test
drwxr-xr-x 6 root root 1024 Nov 27 19:33 ftp
drwx------ 4 test test 1024 Nov 27 22:03 test
drwxr-xr-x 5 root root 1024 Nov 27 19:33 http
drwxr-xr-x 2 root root 12288 Nov 27 19:30 lost+found
# ls –la /home/test
drwx------ 4 test test 1024 Nov 27 22:03 .
drwxr-xr-x 8 root root 1024 Nov 27 22:03 ..
-rw-r--r-- 1 test test 1024 Nov 27 22:03 .bash_logout
-rw-r--r-- 1 test test 1024 Nov 27 22:03 .bash_profile
-rw-r--r-- 1 test test 1024 Nov 27 22:03 .bashrc
File default dapat diganti dengan menggunakan option ke dua yaitu –D :
Ganti HOME default ke direktori /usr :
#useradd –D –b /usr
#useradd –D
GROUP=100
HOME=/usr
INACTIVE=1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
Mengubah User
# usermod
usage : usermod [-u uid [-o]] [-g group] [-G group,….]
[-d home [-m]] [-s shell] [-c comment] [-l new_name]
[-f inactive] [-e expire] [-p passwd] [-L|-U] name
#userdel
usage : userdel [-r] name
# usermod –g 500 test
# grep test /etc/passwd
test :x:200:500::/home/test:/bin/bash
#userdel –r test
#grep test /etc/passwd
Group Identifiers (GIDs)
Setiap user Linux berada dalam satu atau beberapa group. Sebagaimana halnya account-account user, group terdiri atas groupname dan group identification number (GID).
Nilai-nilai GID juga secara historis memiliki integer 16 bit. Sesuai dengan namanya, group-group Linux digunakan untuk mengelompokkan user-user satu sama lainnya. Sebagaimana username, groupname juga diset oleh administrator sistem saat account-account user dibuat. GID user diletakkan mengikuti UID-nya, perhatikan contoh file /etc/passwd :
test:eH5/.mj7NHB3dx:181:100:Test:/home/Test:/bin/ksh
Dalam contoh diatas, dapat dilihat bahwa GID primer anjik adalah 100. Group memberikan mekanisme penanganan atau batasan-batasan tertentu bagi user-user. Group juga digunakan untuk membentengi akses informasi sensitif dan aplikasi-aplikasi berlisensi khsus untuk user tertentu.
File /etc/group terdiri atas database yang memuat daftar setiap group dalam komputer beserta koresponden GID-nya. Formatnya sama dengan file /etc/passwd. Berikut contoh isi file /etc/group yang mendefinisikan lima group wheel, users,netc, internet, dan bebas :
wheel:*:0:root, test
users:*:100:
netc:*:101:setan, devil
internet:*:102:icha, test, coba, support
Membuat Group
Linux telah menyediakan utilitas administrasi group dengan utilitas groupadd. Sebelum melakukan penambahan group baru sebaiknya dilakukan pengecekan apakah group sudah atau belum.
# groupadd
usage : groupadd [-g gid[-o]] [-r] [-f] group
-g nilai group-id
-o Jika optioan ini dijalankan, maka group-id boleh merupakan duplikasi
dari GID yang sudah ada
-r menambah group sebagaimana bagian dari sistem dengan GID lebih
kecil dari 500.
-f force, akan memaksa groupadd untuk menghentikan proses, jika sudah
ada di /etc/group.
# groupadd myschools
# grep test /etc/group
Bila nomor group tidak diberikan, maka sistem akan memberikannya secara otomatis.
Utilitas groupmod dan groupdel dapat digunakan untuk mengubah parameter group atau menghapusnya dengan groupdel.
# groupmod
usage : groupmod [ -g gid [-o]] [-n name] group
Mengganti group-ID
# groupmod –g 123 mygroup
# grep mygroup /etc/group
mygroup:x:123:
Mengganti group-name
# groupmod –n newgroup mygroup
# grep mygroup /etc/group
# grep newgroup /etc/group
newgroup:x:123
Menghapus group
# groupdel
usage : groupdel group
# groupdel newgroup
# grep newgroup /etc/passwd
Perhatian : Sebelum meghapus group, pastikan lebih dahulu bahwa tidak ada pemakai yang terdaftar dalam group tersebut. Periksa di /etc/passwd.
Super User
Setiap sistem Linux secara default memiliki user spesial dalam file /etc/passwd, yang memiliki UID bernilai 0. User ini dikenal juga dengan superuser dan normalnya diberi username root.
Account root adalah identitas yang digunakan oleh sistem operasi untuk menyelesaikan fungsi-fungsi dasar sistem, seperti logging user-user yang masuk dan keluar, me-record informasi accounting, dan mengaturdevice device input/output.
Dengan mengetikkan su tanpa diikuti username akan memberitahu Linux bahwa sistem diminta untuk mengubah ke dalam superuser. Selanjutnya diminta memasukkan password. Setelah password root diketikkan, maka shell akan berjalan dengan UID 0. Saat menjadi superuser, secara otomatis prompt akan berubah menjadi (#) untuk mengingatkan bahwa user berada dalam status sebagai superuser.
$ /bin/su –
password : *******
[root@tester ~]# who am I
root
Jika menggunakan command su untuk berubah ke user lain saat status sebagai superuser, sistem tidak meminta memasukkan password user bersangkutan.
[root@tester ~]# su test
$ who am I
test
Tidak semua user bisa menggunakan perintah su terhadap user root kecuali user tersebut masuk dalam group wheel dalam /etc/group yang memiliki group ID 0. Agar batasan ini bekerja, entri /etc/group tidak boleh dikosongkan, karena jika sikosongkan, semua user bisa mengubah menjadi superuser.
Menambah user
Menambah user-user dalam Linux meliputi tahapan-tahapan sebagai berikut :
- Eksekusi dan mengedit passwd, shadow, dan file group
- Menset password inisial
- Membuat direktori home user
- Mengcopy file-file start-up default
- Mengubah kepemilikan
- Memerika set up account dengan teliti.
File Password: /etc/passwd
File password /etc/passwd secara umum memuat hal-hal sebagai berikut :
- username
- Password terenkripsi, seringkali disimpan dalam /etc/shadow
- UID, nomor yang unik untuk user
- Default GID, group ID user saat mereka login. Untuk mengubah group dapat digunakan perintah /bin/chgrp
Group dan /etc/group
- memungkinkan user melakukan share file dan resource
- Group dibentuk dengan :
*Secara implisit dengan cukup menaruh nomor baru dalam field keempat pada /etc/passwd
*Secara eksplisit dengan menambah entri /etc/group
- /etc/group dapat memilikibentuk field seperti berikut :
group-name:*:GID:users
Membuat Direktori home
- Tambahkan entri-entri file passwd dan shadow
- Gunakan passwd userid untuk menset passwd user
- Buat direktori home untuk user bersangkutan
$mkdir /home/username
- Copy file-file inisialisasi shell
- Buatlah semua file dimiliki oleh user tersebut
# chown –R username:groupname /home/username
Menguji Account
- Gunakan su – username untuk mengetes sebuah account
- Perintah su (substitusi user) memungkinkan merubah menjadi user lain tanpa perlu menutup login.
- “-“ menunjukkan agar membaca semua file-file inisialisasi user
Menghapus User
- Gunakan passwd –l username untuk me-lock account
# userdel -r test perintah ini akan sekalian menghapus direktori $HOME/user