From Technical Knowledge to IT Service Management

Archive for the ‘sysadmin’ Category

Sendmail: quick start

First you have to edit the config file
vi /etc/mail/sendmail.mc
you have to know your smtp server:


dnl # Uncomment and edit the following line if your outgoing mail needs to
dnl # be sent out through an external mail server:
dnl #
define(`SMART_HOST’,`serverSMTP’)
dnl #
define(`confDEF_USER_ID’,“8:12”)dnl
dnl define(`confAUTO_REBUILD’)dnl
define(`confTO_CONNECT’, `1m’)dnl

Then, generate the .cf file with ‘m4′ tool:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

You now have a new config file for our sendmail daemon
Then, restart sendmail:
/etc/init.d/sendmail restart

create a directory tree

If you want to quick, don’t forget to use the ‘-p’ option

wrong way:
[john@host john]$ mkdir dev
[john@host john]$ cd dev
[john@host dev]$ mkdir first
[john@host dev]$ cd first
[john@host first]$ mkdir alpha
[john@host dev]$ mkdir second
[john@host dev]$ ll
[john@host dev]$ cd ..
[john@host john]$ mkdir prod
[john@host john]$ cd prod
[john@host prod]$ mkdir first
[john@host prod]$ mkdir second

good way:
[john@host john]$ mkdir -p dev/first/alpha

best way:
[john@host john]$ mkdir -p dev/{first/alpha,second},prod/{first,second}

Monter une iso

Pour monter directement un fichier iso sous linux:

mount -o loop -t iso9660 fichier.iso /mnt/iso

On a ainsi dans /mnt/iso le contenu de l’iso, ca evite de graver ;-)

run level and /etc/inittab

Description

The numbers associated with the run levels for a specific distribution are listed in the /etc/inittab

#/etc/inittab (in RHEL 3)
# Default runlevel. The runlevels used by RHS are:
# 0 – halt (Do NOT set initdefault to this)
# 1 – Single user mode
# 2 – Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 – Full multiuser mode
# 4 – unused
# 5 – X11
# 6 – reboot (Do NOT set initdefault to this)
#
id:3:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Choose the good runlevel:
Runlevel 0:
it will shutdown your system

Runlevel 1:
It is the single user mode, used by system administrator when you have to fix some problems and everything is going wrong. you’ll be root without password.

Very useful if you forgot your root password, but you have to protect the physical acces to your server.
No user can log in while you are in this runlevel

Runlevel 2:
It is a multi user mode in command line (like the runlevel3) but you don’t have network connection

Runlevel 3:
It is the full multiuser command line mode. (mainly used by every one)

Runlevel 4:
I think it is not really used maybe you can configure it for special purposes…

Runlevel 5:
It is the full multiuser X11 mode.

Runlevel 6:
It will reboot your server

The good choice:
Depending on the server utilisation you have, you’ll choose runlevel 3 or 5

The (very) bad one:
You mustn’t change the initdefault to runlevel 0 (halt) or runlevel 6 (reboot)
because the system will then either immediately shutdown just after starting, or reboot indefinitely….

Changing the inittab configuration:

To make a change you can either edit the conf. file /etc/inittab or use the comand ‘telinit’

[admin@nuxora admin]$man telinit

#
#…. this is an extract ….
#

TELINIT
/sbin/telinit is linked to /sbin/init. It takes a one-character argu-
ment and signals init to perform the appropriate action. The following
arguments serve as directives to telinit:

0,1,2,3,4,5 or 6
tell init to switch to the specified run level.

a,b,c tell init to process only those /etc/inittab file entries having
runlevel a,b or c.

Q or q tell init to re-examine the /etc/inittab file.

S or s tell init to switch to single user mode.

U or u tell init to re-execute itself (preserving the state). No re-
examining of /etc/inittab file happens. Run level should be one
of Ss12345, otherwise request would be silently ignored.

telinit can also tell init how long it should wait between sending pro-
cesses the SIGTERM and SIGKILL signals. The default is 5 seconds, but
this can be changed with the -t sec option.

telinit can be invoked only by users with appropriate privileges.

[admin@nuxora admin]$
[admin@nuxora admin]$

Trap Key:

If the key combination CTRL-ALT-DEL is trapped by one entry in /etc/inittab
then the shutdown command will be called when you’ll press ctrl+alt+del

Everyone who has physical access to the console keyboard could shut the system down.
It will also check if the user is allowed to execute a ‘shutdown’. To prevent this, you can
drop this line from /etc/inittab or modify the execution script:
ca::ctrlaltdel:echo “shutdown is not allowed pressing ctrl + alt + del”

Bash Shell Tips

Native Windows users are reluctant to use Bash shell, even some linux geeks don’t know everything about the very useful shortcuts available in bash shell. But when you use all these shortcuts you can go very quickly ;-)

I’ve tried to compile all of them:
for example
$ Tab Tab –> press ‘$” then ‘Tab’ and another time ‘Tab’

Ctrl + r —> press at the same time ‘Ctrl’ key and ‘r’ key

special ones:

! – repeats the last command
! – execute the (num)th command in history

with TAB

Tab Tab – gives you all the main commands (eventually strating with )
/ Tab Tab – list complete directory structure
* Tab Tab – list directory without hidden one
~ Tab Tab – list users from /etc/passwd
$ Tab Tab – list the System variables
@ Tab Tab – list host(s) from /etc/hosts
= Tab Tab – list the content of a directory like ‘ls’

with CTRL Key

Ctrl + a – Jump to the beginning of the line
Ctrl + b – Move back one char
Ctrl + c – Interrupt the command
Ctrl + d – Delete from under the cursor
Ctrl + e – Jump to the end of the line
Ctrl + f – Move forward one char
Ctrl + h – Backspace
Ctrl + k – Delete to EOL
Ctrl + l – Clear the screen
Ctrl + n – Scroll next command line (read ctrl + p tips)
Ctrl + p – Scroll previous command line
Ctrl + r – Search the history backwards
Ctrl + R – Search the history backwards with multi-occurrence
Ctrl + t – Swap of the last two chars
Ctrl + u – Delete backward from cursor
Ctrl + w – Delete the last word
Ctrl + xx – Move between EOL and current cursor position
Ctrl + x @ – Show possible hostname completions (the same like ‘@ Tab Tab’)
Ctrl + y – paste
Ctrl + z – Suspend/ Stop the command

with ALT Key

Alt + < - Move to the first line in the history
Alt + > – Move to the last line in the history
Alt + ? – Show current completion list
Alt + * – Insert all possible completions
Alt + / – Attempt to complete filename
Alt + . – Yank last argument to previous command
Alt + b – Move backward
Alt + c – Capitalize the word
Alt + d – Delete word
Alt + f – Move forward
Alt + l – Make word lowercase
Alt + n – Search the history forwards non-incremental
Alt + p – Search the history backwards non-incremental
Alt + r – Recall command
Alt + t – Move words around
Alt + u – Make word uppercase
Alt + backspace – Delete the last word (like Ctrl + w)