Linux Flashcards

1
Q

What does uptime tell you? Where does it get its info from?

A

Uptime, logged in user count, load average for past 1, 5, 15 minutes

Reads from binary file /var/run/utmp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name 3 ways to see when the system was last booted.

A

who -b
uptime
last reboot | head -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where can you see steal time? What does it affect? What is too much? What can be done?

A

Steal time can be seen in iostat.

It only applies to virtualization, basically it means a process had to wait for the cpu to complete some other task in a different virtualization instance.

More than 10% for 20+ minutes is no good.

Maybe the host isn’t fast enough to handle everything or maybe it’s just too crowded (in that case move to a less crowded VM).

https://scoutapm.com/blog/understanding-cpu-steal-time-when-should-you-be-worried

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is nice time? Where can you see it? What does it mean?

A

Can bee seen with iostat or top. It’s the amount of time processes with positive priorities are running. If things get busy, some processes will throttle back. Note, negative priority processes do not show up under nice time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

With nice/setpriority, explain which direction from zero is more favorable to the system and which is more favorable to the process. What is the max value both ways?

A

Positive is more favorable to the system, negative is more favorable to the process. 20/-20 are the max/min

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you run a process with altered priority? Why would you want to do this

A

nice

If its non critical you can set a positive priority to allow it to throttle back if system gets busy. You can set a negative value if it’s critical and have privileges but you may want to consider a better design that doesn’t rely on this as system can become unstable if it takes over.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you alter the priority of an already running process?

A

renice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does iostat show you?

A

Averages for time spent in cpu states since boot (or while running at predefined intervals) as well as block device statistics like read per second, total, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is system time % (as opposed to user time %)? Where do you see it?

A

CPU time spent executing system code (aka kernel instructions), non userspace. Iostat or top or similiar. Should be as low as possible, but can spike high for input/output to console or else-wise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can sar do?

A

Basically logs iostat over time but extra ability is it can break down cpu stats by processor with -P ALL so you can see if a single core is going wonky.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to diagnose hardware interrupts?

A

mpstat -P ALL, look where there are lots of interrupts on each processor. cat /proc/interrupts, see if any devices are generating a large number of interrupts, Can use dmesg to look for messages related to the devices with high count.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to get memory info? And more detailed?

A

Free. vmstat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you see your routing table?

A

netstat -r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does netstat -s do? Name some useful things it shows you.

A

Summary of network activity by protocol (since last boot).

How many outing packets were dropped
How many incoming packets had bad addresses
TCP retransmit count
Failed connection attempt count.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you display network connections that are currently listening? Which type of connections will this show? How do you see which programs/pids are using them? How to show only connected?

A

netstat -l

shoes system I-nodes (sockets) and network.

  • t only tcp
  • u only udp
  • p is to show pids
  • a to only show connected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does w do?

A

Shows who is logged on and what they’re doing, cpu time for processes and current process. Can give a username to only see their info. Also shows you the 1,5,15 load averages for the system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What do you use iotop for? How?

A

iotop requires root access, it gives you the the thread ids and for each shows you the priority, the disk read/write throughput, the percentage of time it is spending swapping in, and the percentage of time the process is blocking on io, and the command.

So if you had a lot of iowat time from top, iotop allows you to see exactly what is contributing to that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Whats the different between netstat and ss?

A

ss queries the kernel socket directly, while netstat uses /proc/net/tcp.

netstat is deprecated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is iptraf?

A

Like wireshark, very complicated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Tell me about collectd

A

Plugins to monitor system, like sar but way more.

Gathers constantly, writes at 10 min intervals (can be configured)

Only collects, doesn’t display

config, plugin loading and conf
/etc/collectd/collctd.conf

plain text file with fields and how they are derived or grabbed
/usr/share/collectd/types.db

uses rrd to collect stuff, files stored in, binary format, need rrd tool to read
/var/lib/collectd/rrr/hostname/blah

rrd - round robin database tool
stores time-series data in a circular buffer

Other viewers for collectd data
Nagios

Cacti

MRTG

Ichinga forked from Nagios

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Explain what a LKM is? Where are they stored? What is their extension?

A

Loadable Kernel Module

Not taking up memory and loaded automatically, you manage. Like nvidia driver on linux. Loaded when needed, unloaded when not.

/lib/modules/$(uname -r)/kernel

broken out by type, multiple levels

.ko files (kernel object)

These are just storage, not indicating run or config

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Name two ways to get hostname

A

hostname

uname -n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you see kernel info?

A

uname -a

gives you everything.

24
Q

What is modules.dep? Where is it located? What uses it? What generates it?

A

Text couterpart to binary file modules.bin.dep that defines mapping of dependencies between LKMs.

Located within a specific kernel folder in /lib/modules

Used by tools like modprobe

Generated by depmod

25
Q

When might you want to run depmod? Why?

A

If you or something copied a pre built LKM into /lib/modules. To map its dependencies

26
Q

How do you see currently loaded LKM’s? What info do you get?

A

lsmod

Shows module name, size in bytes, what else is using it

27
Q

How do you unload a LKM?

A

rmmod name_of_module

28
Q

Name two ways to load a LKM.

A

insmod /path/to/module.ko
(find via find, or modinfo)

or

modprobe module_name

29
Q

How to get info on a LKM? What do you need?

A

Just the name of the module, and do modinfo name.

30
Q

How to load an LKM with a specific parameter?

A

modproble module parameter=value

This doesn’t stick on a reboot.

31
Q

How to prevent an LKM from loading? Why would you want to do this?

A

Make a .conf in /etc/modprobe.d/ and include the line
blacklist module_name

module_name can be an alias as well, which can be found via modinfo

Maybe you want to load a different driver, or it cause a problem or interacts poorly.

32
Q

What is /proc/sys? Why might you want to go in there?

A

It’s really the kernel in memory (not real files or filesystem)

You can echo things to the “files” to change kernel parameters in real time, or read the files to view. Changes will be reset after a reboot.

33
Q

What’s the official way to change kernel parameters at runtime? How do you make them permanent?

A

sysctl path.inside.of.proc.sys=value

edit /etc/sysctl.conf and put the line in there but with spaces around the = so
thing.thing.thing = value

34
Q

How to find info about system devices?

A

lspci

  • k will show you kernel driver in use
  • v will show you extra info

lsdev gives you info about devices interrupts, IO, and DMA

35
Q

How to find out about non system devices?

A

lsub only newer than 3.x kernel

lsub -v -d ID will give you info on just one thing

36
Q

How to monitor devices?

A

udevadm monitor

37
Q

How to set rules for devices?

A

/etc/udev/rules.d

higher numbers ovverride lower

38
Q

How can you tell a symlink from a hard link?

A

ls -l, look at inode count, should be more than one with hardlinks, softlinks will show its a link.

39
Q

What’s the main difference between bin and sbin?

A

sbin is stuff only the superuser can run.

40
Q

What does ‘usr’ stand for?

A

Unix system Resources

41
Q

How can you figure out where a command and its info are?

A

whereis shows executable, code, and man pages

42
Q

What does /etc stand for?

A

Extended text configuration

43
Q

What is the /root directory?

A

Root’s home folder.

44
Q

What’s the difference between /var and /tmp

A

/tmp is meant as very fast short lived storage, often aggressively purged by system. in RHEL purged every 10

/var is more permanent, maybe not purged or purged less frequently, usually slower storage (not ram, or slower disk) in RHEL purged very 30 days

45
Q

What’s a difference between restart and reload of a service systemctl? Why do one over the other?

A

Restart stops, then starts, so gets a new PID. Reload will keep the pid the same. If you change a config, you may just want a reload, since it has that config in memory. So not to interrupt other things just reread the config from file and reload the new into memory. Maybe restart if its not working at all.

46
Q

What does POSIX stand for, what is it? What about SUS?

A

Portable Operating System Interface for Unix

Single Unix Specification, alternate spec.

47
Q

What’s the difference between hard links and soft links?

A

Hard links are pointers to inodes. Cannot cross filesystems. Soft links are pointers to filepaths.

48
Q

What does a ‘.’ in ls output for perms indicate? What about a ‘+’?

A

. indicates extended attributes, most likely SELinux context.
+ indicates ACLs.

49
Q

What is SUID? SGID? How you do you see it? How do you set it

A

Set effective user id or group id. You will see an s in the user or group section of ls permissions. It means that process will run with the effective UID of the owner.

First bit of permissions octal.
0 - nothing
2 - SGID
4 - SUID

50
Q

SUID bits don’t work on ______

A

Scripts. anything that begins with a shebang.

51
Q

What is the sticky bit? How do you set it?

A

A ‘t’ at the end of permissions. Anyone can write but only owner of the files can delete.

First digit of perms octal to a 1

52
Q

What is file umask? How do you set it?

A

Files: Default 666, mask 222, result 444.
Dirs: Default 777

umask command shows you current mask and allows you to change but it is NOT persistent (only to shell session)

To make need to change the conditionals in bashrc or bash._profile (in /etc/ not in user versions)

53
Q

Sudoers cheat sheet. Give it to me

A

uid, %group, username should not need a prefix

sudo -l -U user will show you what a user can sudo do

sudoers can do #include sudoers.d/file, the # is not a comment

Format is below, NOPASSWD is optional, leaving off runas means can only run as root
USERS HOSTS = (RUNAS) NOPASSWD COMMANDS

54
Q

How to exit history search back at current line?

A

ctrl-g

55
Q

How to edit a history item as a new command?

A

fc command#

56
Q

How to open prompt line in editor?

A

ctrl-x ctrl-e in emacs mode, escape v in vi mode

57
Q

Explain setuid and setgid bits?

A

Explain!