Basic System Administration: Your Daily Commands As Root
Basic System Administration: Your Daily Commands As Root
Basic System Administration: Your Daily Commands As Root
Becoming root
$HOME is sometimes not /root but instead /; so watch what you delete!
Never execute any regular user's program as root (possible Trojan Horse)
To implement: sudo<command>
Groups are the same as user groups and are differentiated from regular users by a % at
the beginning. The Linux user group "users" would be represented by %users.
You can have multiple usernames per line separated by commas.
Multiple commands also can be separated by commas. Spaces are considered part of the
command.
The keyword ALL can mean all usernames, groups, commands and servers.
If you run out of space on a line, you can end it with a back slash (\) and continue on the
next line.
sudo assumes that the sudoers file will be used network wide, and therefore offers the
option to specify the names of servers which will be using it in the servername position
in Table 9-1. In most cases, the file is used by only one server and the keyword ALL
suffices for the server name.
The NOPASSWD keyword provides access without prompting for your password.
Same concept as the SUID bit in permissions (4000).
sudo examples
sudo command
Examples:
- user1 localhost=/sbin/halt
user1 can halt local system
[user1@student1]$ sudo /sbin/halt
password:
[user1@student1]$ System going down now!
- user2 ALL= NOPASSWD: /sbin/halt
- user3 instructor = /usr/sbin/*
System information
hostname
uname a
dmesg
who, whoami, w, id
last (reboot)
which, where/whereis, apropos
hwclock
date
ulimit (user limits)
sysctl (system limits/settings)
cgroups
/etc/sysconfig
/etc/security
/proc
ps, pstree,
System monitoring
sar
pmap
vmstat,
mpstat
iostat
nstat (network),
pidstat
dstat
free
lsof
top, ntop, iftop, latencytop
ulimit a (view), ulimit n (set) ulimits Hn, ulimits -Sn per user limits,
/etc/security/limits.*
See /etc/security/limits.conf: sysctl q (view), sysctl w (set) system
limits, /etc/sysctl.conf
strace (debugging)
/etc/sysconfig
The /etc/sysconfig directory is where many of the files that control the system
configuration are stored for daemon processes or system services like networking.
Contents vary depending on products installed.
/etc/sysconfig is usually sourced (. /etc/sysconfig) in SYSV startup scripts.
Filesinthe/etc/sysconfig/Directory
amd , apmd authconfig , clock , desktop , devlabel, dhcpd, firstboot, gpm, harddisks,
hwconf, i18n, init, ip6tables-config , iptables-config, irda, keyboard , kudzu, mouse,
named, netdump, network, network-scripts, ifup-xxxx, ntpd, pcmcia, radvd, rawdevices,
selinux, logrotate, samba , sendmail, spamassassin, squid , tux , vncservers, xinetd
/proc
/proc is a virtual filesystem. It's sometimes referred to as a process information pseudofile system. It doesn't contain 'real' files but runtime system information (e.g. system
memory, devices mounted, hardware configuration, etc) for all processes started by init
including PID and startup commands. /proc was developed as a LINUX extension to
keep track of all the complex processes started in the system
For this reason it can be regarded as a control and information centre for the kernel. In
fact, quite a lot of system utilities are simply calls to files in this directory. For example,
'lsmod' is the same as 'cat /proc/modules' while 'lspci' is a synonym for 'cat /proc/pci'. By
altering files located in this directory you can even read/change kernel parameters
(sysctl) while the system is running.
The most distinctive thing about files in this directory is the fact that all of them have a
file size of 0, with the exception of kcore, mtrr and self.
/etc/security
The limits.conf file defines process resource limits for users. (see ulimit)
For network:
# Enable IP spoofing protection
net.ipv4.conf.all.rp_filter=1
# Disable IP source routing
net.ipv4.conf.all.accept_source_route=0
# Ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_messages=1
# Make sure spoofed packets get logged
net.ipv4.conf.all.log_martians = 1
# disable IPv6
net.ipv6.conf.all.disable_ipv6=1
Kernel isolation (test carefully on test system):
Turn on execshield
kernel.exec-shield=1
kernel.randomize_va_space=1
-c
maximum core file size (in 512-byte blocks)
-d
maximum size of data segment or heap (in kbytes)
-f
maximum file size (in 512-byte blocks)
-n
maximum file descriptor plus 1
-s
maximum size of stack segment (in kbytes)
-t
maximum CPU time (in seconds)
-v
maximum size of virtual memory (in kbytes)
-S
soft limit
-H
hard limit
/etc/security/limits.conf
c(ontrol)groups
Cgroups allow you to allocate resourcessuch as CPU time, system memory, network bandwidth, or
combinations of these resourcesamong user-defined groups of tasks (processes) running on a
system.
A *cgroup* associates a set of tasks with a set of parameters for one or more subsystems. A
*subsystem* is a module that makes use of the task grouping facilities provided by cgroups to treat
groups of tasks in particular ways. A subsystem is typically a "resource controller in a hierarchy of
processes.
A cgroup is mounted as a virtual filesystem and can be modified to re-alllocate kernel resources.
Each cgroup is represented by a directory in the cgroup file system containing the following files
describing that cgroup:
- tasks: list of tasks (by pid) attached to that cgroup
- releasable flag: cgroup currently removeable?
- notify_on_release flag: run the release agent on exit?
- release_agent: the path to use for release notifications (this file exists in the top cgroup only) Other
subsystems such as cpusets may add additional files in each cgroup dir.
PAM
PAM Framework
ftp
login
ssh
PAM Library
libpam
conf
Applications
Modules
pam_unix
pam_ldap
pam_securetty
PAM Stack
Modules are stacked (order is important)
Sample PAM configuration in
/etc/pam.d:
interface
auth
auth
auth
auth
control flag
module name
requiredpam_nologin.so
requiredpam_securetty.so
sufficientpam_unix.so
requiredpam_ldap.so
SELINUX Modes/Types
Enforcing: enable and enforce the SELinux
security policy on the system, denying access
and logging actions in /var/log/audit/audit.log
Permissive: enabled but will not enforce the
security policy, only warn and log actions.
Used for troubleshooting SELinux issues
Disabled: SELinux is turned off
Targeted: Specific processes
MLS/STRICT: VERY secure - systemwide
SELINUX Policy
Policy: a set of rules the SELinux security engine that
defines types for file objects and domains for processes,
and user defined (identities) roles to limit the domains that
can be entered.
Strict - minimum access
Targeted specific processes
Unconfined not under SELINUX control, outside
SELINUX context
SELINUX Commands
Common options:
-a print all processes involving terminals
-e print environment and arguments
-l long listing
-u print user information
-xi nclude processes with no terminals
Common options:
-e print all processes
-f print full listing
-l long listing (more info than -f)
pstree
Process Management
Process Management
nohup command run a process after logging off. Nohup.out contains job
output.
Runlevels
RunLevel
Generic
FedoraCore
Slackware
Debian
Halt
Halt
Halt
Halt
Single-user mode
Single-user mode
Single-user mode
Single-user mode
Basic multi-user
mode (without
networking)
User definable
(Unused)
Multi-user mode
Multi-user mode
Not used
Not used
X11 with
KDM/GDM/XDM
(session managers)
Multi-user mode
Multi-user mode
Reboot
Reboot
Reboot
Reboot
service/chkconfig
Seesystemd(RHEL/Fedora/Centos)
Seeupstart(Debian/Ubuntu)
service<service name> start/stop/restart/status
Backup/Restore
cpio - can back up individual files/directories, handles special files, packs data
tighter than tar, skips bad spots on media on restore, use with find (some
versions of find have -cpio option for this purpose)
tar - backs up directory trees, does not back up special files, poor error
handling with media errors, does not pack blocks (GNU tar solves some of
these problems). Some LINUX/UNIX systems have built-in compress with z
flag.
Backup Strategy
Can use logical backups in conjunction with find command exec option (next panel) for
differential or incremental backups
find
findexamples
find
find
find
find
Disk management
df
mount / umount
du | sort rn | more
User management
Set system account parameters (e.g., password aging, account expiration, quotas,
login scripts - /etc/profile, /etc/bashrc etc)
/etc/passwd-logname:passwd:uid:gid:user info:home:shell
/etc/group:group:passwd:gid:members
User Security
Password aging:
get: chage -l userid
set: chage -M 60 -m 7 -W 7 userid
Verify no password IDs: awk -F: '($2 == "") {print $1 }' /etc/shadow | grep /etc/passwd
Make sure they are /bin/nologin
SYSLOG
Each system message sent to the syslog server has two descriptive labels
associated with it that makes the message easier to handle.
- The first describes the function (facility) of the application that
generated it. For example, applications such as mail and cron generate
messages with easily identifiable facilities named mail and cron.
- The second describes the degree of severity of the message.
SYSLOG
Severity:
Level:Keyword:Description
SYSLOG
Example:
*.info;mail.none;authpriv.none;cron.none /var/log/messages
Note other services may record messages in other files (e.g. sendmail)
System shutdown
Other commands: halt, reboot, Ctrl-Alt-Del may bypass some processing. Not
recommended for production systems.
last(reboot)displays info