Basic System Administration
Total Page:16
File Type:pdf, Size:1020Kb
Basic System Administration Your daily commands as root Becoming root • Avoid login as root over network (denied by default) • Use "/bin/su -" command from your regular account - “-” runs user LOGIN scripts - root can su to any userid without password. - Note utility for NOLOGIN ID’s. • $HOME is sometimes not “/root” but instead “/”; so watch what you delete! • Remove the current working directory (".") from your PATH • Never execute any regular user's program as root (possible Trojan Horse) • Use SSH, not TELNET over network to avoid sniffers root access - sudo • visudo (as root) creates /etc/sudoers file in the following format: usernames/group servername = (usernames command can be run as) command • 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 … to run the command as USER 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 … user2 can halt any system w/o password - user3 instructor = /usr/sbin/* … user 3 can run any command in /usr/sbin System Administration tools • man: Sections - 1 commands, 2 system calls, 3 C library routines, 4 devices and networks, 5 file formats, 6 games and demos, 7 miscellaneous, 8 system administration • info – textinfo man page • vi editor (front-end to a lot of utilities) • su, sudo • df/du, mount • dump/restore, dd, cpio, tar, rmt, find, rsync • ps, at, batch, crontab, anacron, watch, kill, nice, nohup, killall, • useradd, usermod, userdel • groupadd, groupmod, groupdel • who, whoami • syslog • system configuration files – /etc System information • hostname • uname –a • dmesg • who, whoami • last (reboot) • which, where cmd • 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 • 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. • Files in the /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 pseudo- file 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 • Central directory for system defaults • The limits.conf file defines process resource limits for users. (see ulimit) • opasswd - Store old passwords. • access.conf used to allow or restrict access to the system. • chroot.conf used to restrict users to there home directories • console.apps contains files which are same as service names. • console.perms and console.perms.d directory determine the permissions that will be given to • The rest are PAM (Program Authentication Module) related. sysctl – system limits • sysctl –q, sysctl –w, sysctl –p file, sysctl -A • /etc/sysctl.conf 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 ulimit – user limits • ulimit - set user limits • -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 resources—such as CPU time, system memory, network bandwidth, or combinations of these resources—among 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 • Pluggable Authentication Module • Centralized authentication mechanism • “Plug in” different authentication methods • Different services can have different authentication policies • Highly secure systems can require multiple passwords to authenticate PAM Framework • ftp login ssh Applications PAM Library conf libpam Modules pam_unix pam_ldap pam_securetty PAM Stack • Modules are stacked (order is important) • Sample PAM configuration in /etc/pam.d: interface control flag module name auth required pam_nologin.so auth required pam_securetty.so auth sufficient pam_unix.so auth required pam_ldap.so Security Enhanced LINUX • Kernel level security included since 2.60 kernel • Not an application interface. But sends access return codes to applications. • Can be combined with ACLs • /etc/selinux directory • Old gui system-config-selinux, new gui: policycureutils-gui • BE CAREFUL with changes. Especially deleting files. • See “enforcing=0” or “selinux=0” on Grub edit menu • Protects, files, processes, applications • Based on security “context” An SE Linux security context is comprised of three parts: an "identity", a "role", and a "type" for users and files or "domain" for processes. Default context for root, the role is sysadm_r, and the domain is sysadm_t. • Configuration directory: /etc/selinux directory 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 Access Control • Type Enforcement (TE): Type Enforcement is the primary mechanism of access control used