Informations from the Terminal

System:

# uname -a                                                                  # Get the kernel version (and BSD version)
# lsb_release -a                                                          # Full release info of any LSB distribution
# cat /etc/pisilinux-release                                    # Get Pisi Linux version

# hostname                                                       # system’s host name
# hostname -i                                                   # Display the IP address of the host. (Linux only)
# man hier                                                         # Description of the file system hierarchy
# last reboot                                                     # Show system reboot history

H a r d w a re I n fo rma t io ns

# dmesg                                                             # Detected hardware and boot messages
# lsdev                                                                # information about installed hardware
# dd if=/dev/mem bs=1k skip=768 count=256 2>/dev/null | strings -n 8       # Read BIOS

 

# cat /proc/cpuinfo                                         # CPU model
# cat /proc/meminfo                                     # Hardware memory
# grep MemTotal /proc/meminfo              # Display the physical memory
# watch -n1 ‘cat /proc/interrupts’               # Watch changeable interrupts continuously
# free -m                                                          # Used and free memory (-m for MB)
# cat /proc/devices                                       # Configured devices
# lspci -tv                                                         # Show PCI devices
# lsusb -tv                                                        # Show USB devices
# lshal                                                              # Show a list of all devices with their properties
# dmidecode                                                 # Show DMI/SMBIOS: hw info from the BIOS

 

L o a d, s ta t i s t ic s a nd me s s a g e s

# top                                                                    # display and update the top cpu processes
# vmstat 2                                                        # display virtual memory statistics
# tail -n 500 /var/log/messages                  # Last 500 kernel/syslog messages
# tail /var/log/warn                                         # System warnings messages see syslog.conf

Users

# id                                                           # Show the active user id with login and group
# last                                                       # Show last logins on the system
# whoami                                               # Show who is logged on the system
# groupadd admin                               # Add group “admin” and user colin (Linux/Solaris)
# useradd -c “Stefan Gronewold” -g admin -m groni
# usermod -a -G <group> <user>        # Add existing user to group
# groupmod -A <user> <group>          # Add existing user to group
# userdel groni                                       # Delete user groni
# adduser groni                                    # Add user groni (interactive)
# rmuser groni                                       #Delete user  (interactive)
# pw groupadd admin                         # Use pw on
# pw groupmod admin -m newmember     # Add a new member to a group
# pw useradd groni -c “Stefan Gronewold” -g admin -m -s /bin/tcsh
# pw userdel groni; pw groupdel admin

Encrypted  passwords are stored  in/etc/shadow and  /etc/passwd.

Limits

Some application require higher limits on open files and sockets (like a proxy web server,database). The default limits are usually too low.

Per shell/script
The shell limits are go verned by ulimit.The status is checked with ulimit -a.For example to
change the open files limit from 1024 to 10240 do: # ulimit -n 10240 # This is only valid within the shell
The ulimit command can be used in a script to change the limits for the script only.

Per user/process
Login users and applications can be configured in /etc/security/limits.conf. For example:
# cat /etc/security/limits.conf
* hard nproc 250 # Limit user processes
asterisk hard nofile 409600 # Limit application open files

System wide
Kernel limits are set with sysctl. Permanent limits are set in /etc/sysctl.conf.
# sysctl -a                                               # View all system limits
# sysctl fs.file-max                              # View max open files limit
# sysctl fs.file-max=102400              # Change max open files limit
# echo “1024 50000” > /proc/sys/net/ipv4/ip_local_port_range # port range
# cat /etc/sysctl.conf
fs.file-max=102400                             # Permanent entry in sysctl.conf
# cat /proc/sys/fs/file-nr                   # How many file descriptors are in use

Runlevels

Once booted,the kernelstarts initwhichthenstarts rcwhichstartsallscripts belongingtoa
runlevel.Thescriptsarestoredin/etc/init.dandarelinkedinto/etc/rc.d/rcN.dwithNtherunlevel
number.
The default runlevel is configured in /etc/inittab. It is usually 3 or 5:
# grep default: /etc/inittab
id:3:initdefault:
The actual runlevel can be changed with init. For example to go from 3 to 5:
# init 5                                                      # Enters runlevel 5
0                                                                Shutdown and halt
1                                                                Single-User mode (also S)
2                                                                Multi-user without network
3                                                                Multi-user with network
5                                                                Multi-user with X
6                                                                Reboot

Kernel modules

# lsmod                                             # List all modules loaded in the kernel
# modprobe isdn                            # To load a module (here isdn)

PROCESSES

Listing and PIDs

Each process has a unique number, the PID. A list of all running process is retrieved with ps.
# ps -auxefw # Extensive list of all running process
How ever more typical usage is with a pipe or with pgrep
# ps axww | grep cron
586 ?? Is 0:01.48 /usr/sbin/cron -s
# ps axjf                                          # All processes in a tree format (Linux)
# ps aux | grep ‘ss[h]’                  # Find all ssh pids without the grep pid
# pgrep -l sshd                              # Find the PIDs of processes by (part of) name
# echo $$                                       # The PID of your shell
# fuser -va 22/tcp                        # List processes using port 22 (Linux)
# pmap PID                                 # Memory map of process (hunt memory leaks) (Linux)
# fuser -va /home                       # List processes accessing the /home partition

Signals/Kill

Terminate or send a signal with kill or killall.

# ping -i 60 cb.vu > ping.log &
[1] 4712
# kill -s TERM 4712                           # same as kill -15 4712
# killall -1 httpd                                  # Kill HUP processes by exact name
# pkill -9 http                                     # Kill TERM processes by (part of) name
# pkill -TERM -u www                      # Kill TERM processes owned by www
# fuser -k -TERM -m /home           # Kill every process accessing /home (to umount)

Important signals are:
1 HUP(hang up)
2 INT(interrupt)
3 QUIT(quit)
9 KILL(non-catchable, non-ignorable kill)
15 TERM(software termination signal)

 

FILE SYST EM

Permissions
Changepermissionandownershipwith chmodand chown.Thedefaultumaskcanbechangedforall
usersin/etc/profileforLinuxor/etc/login.confforFreeBSD.Thedefaultumaskisusually022.The
umask is subtracted from 777, thus umask 022 results in a permission 0f 755.
1 –x execute # Mode 764 = exec/read/write | read/write | read
2 -w- write # For:       |–  Owner  –|   |- Group-|   |Oth|
4 r– read
ugo=a u=user, g=group, o=others, a=everyone

# chmod [OPTION] MODE[,MODE] FILE         MODE is of the form [ugoa]*([-+=]([rwxXst]))
# chmod 640 /var/log/maillog                           # Restrict the log -rw-r—–
# chmod u=rw,g=r,o= /var/log/maillog            # Same as above
# chmod -R o-r /home/*                                 # Recursive remove other readable for all users
# chmod u+s /path/to/prog                       # Set SUID bit on executable (know what you do!)
# find / -perm -u+s -print                            # Find all programs with the SUID bit
# chown user:group /path/to/file             # Change the user and group ownership of a file
# chgrp group /path/to/file                        # Change the group ownership of a file
# chmod 640 `find ./ -type f -print`        # Change permissions to 640 for all files
# chmod 755 `find ./ -type d -print`       # Change permissions to 755 for all directories