Linux Administrator ( Fundamental)

Mr.KriangsakNamkot Trainer & Director Jodoi IT&Service Co.,Ltd. [email protected] [email protected] http://www.jodoi.com

Linux Administrator ( Fundamental)

Day 3

9:00 am -12.00 am -Mount & Unmount -SSH Server -Lab SSH

1:00 pm -4.00 pm -Crontab - -

1 Mount & Unmountflash drive

[root@jodoi-server2 ~]# # tail -f /var/log/messages Jul 16 05:51:53 jodoi-server kernel: sda: sda1

[root@jodoi-server2 ~]# lsmod| grepusb usb_storage 77857 0 scsi_mod 141717 5 ,scsi_dh,usb_storage,libata,sd_mod

[root@jodoi-server2 ~]# lsusb Bus 001 Device 001: ID 0000:0000 Bus 001 Device 002: ID 0930:6545 Toshiba Corp. Kingston DataTraveler2.0 Stick (4GB) / PNY Attache4GB Stick Bus 002 Device 001: ID 0000:0000

Mount & Unmountflash drive

[root@jodoi-server ~]# lsusb Bus 001 Device 002: ID 1005:b113 ApacerTechnology, Inc. Handy Steno 2.0/HT203

[root@jodoi-server /]# mkdirflashdir [root@jodoi-server /]# mount /dev/sda1 /flashdir/

[root@jodoi-server /]# cdflashdir/ [root@jodoi-server flashdir]# ls

[root@jodoi-server /]# umount/dev/sda1

2 SSH Server

SecureShell or SSH is a networkprotocolthat allows data to be exchanged using a securechannelbetween two networked devices. sshd -OpenSSHSSH daemon sshd (OpenSSHDaemon) is the daemon program for ssh. sshd can be configured using command-line options or a configuration file ( by default sshd_config ) ssh -OpenSSHSSH client (remote login program)

SSH Server [root@jodoi-server ~]# vi /etc/ssh/sshd_config ~ #Port 22 Port 2222

#Protocol 2,1 Protocol 2

#PermitRootLoginyes PermitRootLoginno

#MaxAuthTries6 MaxAuthTries3

#MaxSessions10 MaxSessions5

~ :wq!

3 SSH Server

[root@jodoi-server ~]# /etc/init.d/sshdrestart Stopping sshd: [ OK ] Starting sshd: [ OK ]

[root@jodoi-server ~]# service sshdrestart Stopping sshd: [ OK ] Starting sshd: [ OK ]

[root@jodoi-server ~]# netstat-tanp|grepssh tcp 0 0:::2222 :::* LISTEN 5432/sshd

[root@jodoi-server ~]# ps-ef|grepssh root 5432 1016:48 ? 00:00:00/usr/sbin/sshd

SSH Server

[root@jodoi-server ~]# ssh127.0.0.1 ssh: connect to host 127.0.0.1 port 22: Connection refused

[root@jodoi-server ~]# ssh-p 2222 127.0.0.1 The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. RSA key fingerprint is 1d:d1:d8:ba:08:d8:0e:a4:c4:6f:42:51:f5:b3:fa:e4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts. [email protected]'s password: ******

4 SSH Server

[root@jodoi-server ~]# ssh-p 2222 [email protected] [email protected]'s password: **** Last login: Tue Jan 13 16:36:30 2009 from 192.168.1.102 [jodoi@jodoi-server ~]$

[root@jodoi-server ~]# ssh-p 2222 [email protected] The authenticity of host '192.168.1.212 (192.168.1.212)' can't be established. RSA key fingerprint is 1d:d1:d8:ba:08:d8:0e:a4:c4:6f:42:51:f5:b3:fa:e4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.212' (RSA) to the list of known hosts. [email protected]'s password: **** Last login: Tue Jan 13 16:55:22 2009 from jodoi-server.com

SSH Server

5 SSH Server

SSH Server

6 RPM

Redhat Package Manager http://www.rpm.org/RPM-HOWTO/

#rpm –ivh filename.rpm ( Install ) #rpm –Uvh filename.rpm ( Upgrade )

[root@doi-server ~]# rpm -qa redhat-logos-1.1.26-1.centos4.4 basesystem-8.0-4 glibc-2.3.4-2.25 ~ [root@doi-server ~]# rpm -qa ntp ntp-4.2.2p1-9.el5.centos.2.1

Used Shell Commands date -print or set the system date and time [root@jodoi-server ~]# date Mon Jan 12 13:44:50 ICT 2009

# date MMDDhhmmYYYY [root@jodoi-server ~]# date 011215302009 Mon Jan 12 15:30:00 ICT 2009 ntpdate -set the date and time via NTP [root@jodoi-server ~]# ntpdate-b time1.nimt.or.th 12 Jan 15:54:42 ntpdate[3199]: step time server 203.185.69.60 offset 262.750732 sec [root@jodoi-server ~]# date Mon Jan 12 15:54:57 ICT 2009

7 Used Shell Commands

# yum install ntp Transaction Summary ======Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s)

Total download size: 1.3 M Is this ok [y/N]: y Running Transaction Installing: ntp ######################### [1/1] Installed: ntp.i386 0:4.2.2p1-7.el5 Complete!

CRON jobs crontab -maintain crontabfiles for individual users -l option causes the current crontab to be displayed on standard output.

-r option causes the current crontabto be removed.

-e option is used to edit the current crontabusing the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontabwill be installed automatically.

SEE ALSO crontab(5) , cron(8)

8 CRON jobs

[root@jodoi-server /]# man 5 crontab

The time and date fields are:

field allowed values ------minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names)

CRON jobs

[root@jodoi-server /]# man 5 crontab

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: ``1,2,5,9'', ``0-4,8-12''. Step values can be used in conjunction with ranges. Following a range with ``/'' specifies skips of the number's value through the range. For example, ``0-23/2'' can be used in the hours field to spec-ifycommand execution every other hour (the alternative in the V7 stan- dardis ``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are also permitted after an asterisk, so if you want to say ``every two hours'', just use ``*/2''.

9 CRON jobs

[root@jodoi-server /]# crontab -l no crontab for root

[root@jodoi-server ~]# ntpdate-b time1.nimt.or.th 27 Jan 10:26:15 ntpdate[2886]: step time server 203.185.69.60 offset 420.699104 sec

[root@jodoi-server ~]# crontab -e 18 16 * * * cp -fr /var/log/* /tmp/log/ :wq! [root@jodoi-server ~]# /etc/init.d/crondrestart Stopping crond: [ OK ] Starting crond: [ OK ]

[root@jodoi-server log]# tail -f /var/log/cron Jan 27 10:15:03 jodoi crond[2862]: (CRON) STARTUP (V5.0) Jan 27 10:16:01 jodoi crond[2872]: (root) CMD (cp /var/log/* /tmp/log/)

CRON jobs

[root@jodoi-server ~]# vi test.sh mkdirlog cp -fr/var/log/* log

[root@jodoi-server ~]# chmod777 test.sh

[root@jodoi-server ~]# ./test.sh

# crontab-e 28 10 * * * mkdir/tmp/test5 48 10 * * * ./test.sh 7 11 * * * /etc/init.d/httpdstop 8 11 * * * /etc/init.d/httpdstart

10 Web Server ( Apache ) httpd -Apache Hypertext Transfer Protocol Server httpdis the Apache HyperTextTransfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process.

[root@jodoi-server /]# rpm -q httpd httpd-2.2.3-31.el5.centos

[root@jodoi-server /]# vi /etc/httpd/conf/httpd.conf

This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See for detailedinformation.

Web Server ( Apache )

[root@jodoi-server /]# vi /etc/httpd/conf/httpd.conf ~ #Listen 12.34.56.78:80 Listen 80

# DocumentRoot"/var/www/

# # ServerAdmin [email protected] # DocumentRoot/www/docs/dummy-host.example.com # ServerNamedummy-host.example.com # ErrorLoglogs/dummy-host.example.com-error_log # CustomLoglogs/dummy-host.example.com-access_log common #

11 Web Server ( Apache )

[root@jodoi-server /]# /etc/init.d/httpdrestart Stopping httpd: [FAILED] Starting httpd: [ OK ]

[root@jodoi-server /]# service httpdrestart Stopping httpd: [ OK ] Starting httpd: [ OK ]

[root@jodoi-server /]# ps -ef |grep http root 27794 1 0 10:08 ? 00:00:00 /usr/sbin/httpd apache 27796 27794 0 10:09 ? 00:00:00 /usr/sbin/httpd apache 27797 27794 0 10:09 ? 00:00:00 /usr/sbin/httpd apache 27798 27794 0 10:09 ? 00:00:00 /usr/sbin/httpd apache 27799 27794 0 10:09 ? 00:00:00 /usr/sbin/httpd apache 27800 27794 0 10:09 ? 00:00:00 /usr/sbin/httpd

Web Server ( Apache )

[root@jodoi-server /]# netstat-tanp|grep80 tcp 1 0 192.168.1.212:54311 195.220.108.108:80 CLOSE_WAIT 2340/python tcp 1 0 192.168.1.212:53106 209.132.176.120:80 CLOSE_WAIT 2340/python tcp 1 0 192.168.1.212:40335 193.1.193.67:80 CLOSE_WAIT 2340/python tcp 0 0 :::80 :::* LISTEN 27794/httpd

[root@jodoi-server /]# netstat-tanp|grephttp tcp 0 0 :::80 :::* LISTEN 27794/httpd tcp 0 0 :::443 :::* LISTEN 27794/httpd

12 Web Server ( Apache )

Webmin

Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more. Webminremoves the need to manually edit Unix configuration files like /etc/passwd, and lets you manage a system from the console or remotely. See the standardmodulespage for a list of all the functions built into Webmin, or check out the screenshots.

http://www.webmin.com/

13 Webmin

[root@jodoi-server ~]# wget http://prdownloads.sourceforge.net/webadmin/webmin- 1.500.tar.gz [root@jodoi-server ~]# tar -zxvfwebmin-1.500.tar.gz

[root@jodoi-server ~]# cdwebmin-1.500

[root@jodoi-server webmin-1.500]# ./setup.sh Web server port (default 10000): Login name (default admin): Login password:

Webmin

[root@jodoi-server webmin-1.500]# netstat-tanp|grep10000 tcp 0 00.0.0.0:10000 0.0.0.0:* LISTEN 6889/ https://192.168.1.212:10000/

14 Webmin https://192.168.1.212:10000/

Webmin

Change password user admin

[root@jodoi-server webmin-1.520]# ./changepass.pl /etc/webminadmin 1234

Updated password of Webminuser admin

15 X windows Basic X-Windows wish to use a graphical interface so tried to run startx [root@jodoi-server ~]# startx or You must change mode command to GuiWindows by [root@jodoi-server ~]# vi /etc/inittab # ~ # 0 -halt (Do NOT set initdefaultto this) # 1 -Single user mode # 2 -Multiuser, without NFS (The same as 3, if you do not have networking) # 3 -Full multiusermode # 4 -unused # 5 -X11 # 6 -reboot (Do NOT set initdefaultto this) id:5:initdefault: # ~ [root@jodoi-server ~]# shutdown –r now

X windows

16 X windows

17