All Flashcards
what’s ldd
see where are the shared libraries of a command. ld.so is the service that permits that
whats the package managers of debian
apt , which use “ dpkg “
difference between remove vs purge in package managers :
remove vs keep conf files.
where are the APT repositories
/etc/apt/sources
whats the APT repo types (4)
- Main : Cannonical supported free and open source packages
- Universe : Communiy-maintained free and open source packages
- Restricted : Propreitary driver packages
- Multiverse : Software with copyrights/legal issues
whats the package managers of Red Hat
yum , which use the “ rpm “
How’s the graphical overlay for rpm called
gnorpm
where is the rpm database located?
/var/lib/rpm
In RPM, whats the difference between using the longname vs shortname packages?
shortname for latest version and if no confilct exist. longname otherwise (with version number)
what’s the two checks for package integrity in rpm
MD5 (package integrity) PGP (identity of distributor)
how to check or import a rpm package signature :
-K = verify signature -rpm –import [URL]
What’s DNF?
the next-gen, python based version on yum. it is more reliable and consistent and easyer to configure.
What’s the SUSE equivalent of yum?
zypper
What’s used for synching a mirroring repos between many SUSE systems
Repository Mirroring Tool (RMT)
difference between OVA vs OVF
each OVF file is always only 1 VM. OVA can contain one on more OVF files.
difference between thin vs thick VM provisioning
thin is the disk space is declared, but isnt all allocated at the beginning
what’s the 4 stages of the Linux boot process
- Boot loader phase
- Kernel phase
- Early user phase (initial RAM disk)
- Init process
hows the old method for providing an early user space filesystem called?
initrd, which is creating a /dev/ram device, with mkinitrd [image] [kernel]
how’s the newer method for providing an early user space filesystem called?
initramfs, which use the dracut [imgfile] to create a initial filesystem inside the RAM
Name of the improvement on PXE that enables more boot options.
iPXE
what are 4 bootloaders of linux?
- LILO : old and less-configurable
- GRUB : v1 or v2, the one of choice (almost always GRUB2 now).
- SYSLINUX : other boot loader, not seen much anymore since UEFI
- Loadlin.exe : Linux boot loader that runs under DOS or Microsoft Windows. It allows the Linux system to load and replace the running DOS/Windows without altering existing DOS/Windows system files.
how do you count the Partition vs the devices
partitions are counted from 1 and devices from 0 (only exception is GRUB1 that count devices from 1)
difference vmlinux vs vmlinuz file?
vmlinuz (compressed) vmlinux (not compressed)
What key to press to access cmd line in grub
C
name of the utility that allows you to inspect performance statistics regarding system bootup as well as current state information
systemd-analyze
command that allows you to find culprit for bootup issues
systemd-analyse blame
journal, networking, and logging daemons name for systemd
journald, networkd, logind
what are ‘units’ and what are their file extension?
“units” are files that represents the config of a service in systemd, they are “.service” files
located at (in order of precedence) :
• /usr/lib/systemd/system/ : installed with the distribution
• /run/systemd/system/ : Units that have been created at runtime
• /etc/systemd/system/ : Controlled by the sysadmin, have precedence over all other units!!! (this is where units are created when using systemctl enable)
how does systemd start at a different runlevel (ex: 1, single user mode)?
Can use “telinit [RUNLEVEL]” to change it. The .target file will correlate to a specific runlevel (0-6). 0 = poweroff, 6 = reboot .
how does SYSVINIT start at a different runlevel by default?
/etc/unittab = IN SYSVINIT : first file read, it have a line that shows “id:3:initdefault” this number 3, or other number will be the default runlevel for the system. init [#] = change current runlevel
what is Masking a service?
disabling a service dosent mean some of its dependencies wont be loaded during init. to prevent this from happening, mask the service with “mask”. This create a symbolic link to /dev/null
whats the command to change a hostname without breaking anything?
hostnamectl set-hostname [hostname]
halt the system and then power it off (gentle for the system)
halt -p OR shutdown -P
*
reboot = shutdown -r
only halt the machine = shutdown -H
(shutdown -k = kidding, send a message that it wills shutdown, to scare users off the system but dosent actually do anything.)
command that show process, and what is the most common options?
ps -aux (a=show process from all users, -u=show user infos, x=also show process without a terminal attached.
typical block size of a block device
512 bytes
What are Pages :
What is the Cache :
What are Slabs :
What are Pages : The kerneel uses pages to manage memory on a system.
What is the Cache : Cache the page write to caches.
What are Slabs : Caches are made of slabs. Typically 1 slab = 1 page
SIGHUP (1) =
hang up and restart process. Also called “bounce”, so program can re-read its config file.
SIGINT (2)
Interrupt process (Ctrl+C)
SIGKILL (9)
kill process (the hard way) [kill -9 PID]
SIGTERM (15)
erminate the signal (the polite way) [default kill command]
SIGTSTP (20)
(Ctrl+Z) Stop the terminal, and pause the process while putting it in background
SIGSTOP (23)
stop execution (the hard way too)
difference between kill vs killall
kill-9 [#PID] stops a process, while killall stop processes based on a search (often a search with pgrep !)
what’s pgrep
used to find commands, usually before using killall
list open file
lsof
4 ways to do job control (putting a job in the backgroud) :
- using jobs : [jobs = shows jobs, bg = puts in bg, fg = bring back in fg] + indicated default acted-upon job, and - mean previous job
- [command] & = run the command in background mode
- CTRL+Z = suspend current process and put it in “bg”
- Using “screen”
2 commands, to start a program with lower priority (10) and change a running program’s priority :
nice -n 10 [program] = to start a program with lower priority (10)
renice -n 10 [PID] = change the priority of the specified process
- nice value (niceness) ranges from -20 (highest priority value) to 19 (lowest priority value) and the default is 0
whats the command to see most used processes, and whats its most used controls?
top “space khindr” :
spacebar = refresh
k = prompt to kill process
h = help
i = toggle display of interactive and zombie processes
n = prompt number of processes to display
d = used when running the process to specify refresh rate (ex : top -d 1)
r = prompt for renice
single command that lets you run another command and the logout while command keep running
nohup [command] . ( Can also use screen for that. )
how does screen works? :
- Ctrl+A to do anything in screen ***
- CTRL+A C = Open a new screen terminal
- CTRL+A [P,N] = Open Previous or Next terminal
- CTRL+A “ (double quotation mark) = shows all open windows and let you chose one
- CTRL+A D = Detatch the session ! (so you can log off and it keeps going)
- CTRL+A X = to lock screen (password in home folder under .screenrc)
- screen -ls = shows all detatched screens!
- screen -r [PID] = reattach that screen
- screen [SomeProgram] = starts that program in a new screen automatically
- exit to close a screen terminal
how to refer to another user’s home directory? :
~username
what does [abc123] means?
it means “any caracter from this set”
2 commands for determining file type
file and stat
whats the difference between hard links and symbolic links ?
hard link : refers directly to the inode of a file. Symbolic links : refer directly to the file name, which refers to the inode
how to correctly copy dir1 into dir2 :
cp -r dir1/* dir2
how do you refer to the file address on a remote systems?
[remote username]@[remote address]:[file destination]
what is the option on commands ssh and scp to provide a private key? :
-i [private key]
Command to synchronise data on a system, or between systems, and how does it function? :
rsync -ar [source][destination]
(and to enable delete when syncing : –delete)
-z = for compression, useful when transfering over the network
Command to compare two files, and its most used options :
diff -qry
q=quiet(less verbose), -r=recursive, y=show files in two columns next to eachothers
How to patch file1 so that it had the changes of file1 :
with patch and diff like this:
diff /etc/file1 /etc/file2 > /etc/somefile.patch; patch /etc/file1 < /etc/somefile.patch
does mv need recursive option added?
no, mv does not have any recursive -r option to add. careful tho because will on a lot of distribution overwrite existing files
how to make many directories levels at once?
-p : remove or add a whole subdirectory list tree in one go, ex : mkdir -p dir1/dir2/dir3/dir4
difference rmdir and rm :
rmdir dosent have a recursive option. thats why its probably better to always use rm instead to remove files and folders. use rm -r to recursive remove folders.
what are 3 ways of finding a file on a system? :
1- find (slow and methodical: find [startpath] [-option] [argument]),
2- locate (quicker, searcg trough a database, updatedb = update the db immidiately, -i = case insensitive),
3- whereis (quickest, only work with commands to show its basic files locations, ex: whereis ls )
with grep, how to shows a numeric count of times it matches
-c
with grep, prints the filename for each occurence
-H
make grep pattern not case sensitive :
-i
grep only shows the filename and nothing else :
-l
grep recursively read and process a whole directory :
-r
grep whole words only, the string cant be attached to another word:
-w
grep only return lines that dont match :
-v
grep compare with a term file (2 ways) :
fgrep -f searchtermsfile.txt filetosearch.txt OR grep -F
grep match word1 OR word2 (2 ways) :
egrep ‘(word1|word2)’ file OR grep -E
regular expressions :
. = replace a single caracter
? = replace a single optional caracter
* = replace any number of caracter, from, zero to any
+ = item must be matched at least once, and can be matched many times
{n} = the item is matched n times
{n,} = the item is matched n times or more
{n,m} = the item is matched n to m times
[^e] = the expression e cannot be matched
\ or e$ = result must finish with this expression
[abc] = result can contain a, b and/or c
command to shows the output in a easely naviguable output :
less
command to return all the PATH and alias used to run a particular command? :
which -a [command]
what is the file permission on a symlink? :
it is always “rwxrwxrwx”, by changing the permission on a symlink, it instead change the permissions on the target. symlink can even point to another filesystem or drive.
what is data stream 0?
0 = /dev/stdin/ = /proc/self/fd/0 = what most programs accepts as input.
what is data stream 1 and 2?
1 = /dev/stdout/ 2 = /dev/stderr/
How to NOT show stderr on a terminal command result?
[command] 2> /dev/null
How to separate good and bad data in different files:
[command] > gooddata.txt 2> baddata.txt
what is a heredocument (also called “heredoc”) ?
a chosen word, that can be used to start and stop a input. ex: cat << DONE >hi >bye >DONE hi bye
command to determine which terminal device you are connected to right now :
tty
difference between these 3: ; && ||
; = execute commands independently of eachothers && = only execute second command if the first command has exis status of 0 (success) || = opposite of &&, bevause the second command will be attempted ONLY if the first command fails.
what does the backtick around a command does? and how else can you achieve same thing? :
execute this command on its own first. useful to put result of a command in a variable. Same can also be done with $(command)
how to let one standard output go normally, while simultaneaously sending that same output to a file (so making 2 outputs from 1)?
tee [filename]
how to takes every single lines of output from another previous command and pass it to the next one? :
[previous command] | xarg [next command]
difference between echo and printf
echo shows text on a new line, printf show it on the same line (more like a coding thing)
how to cat a document backward? (backward line by line)
tac
how to view and follow the tail of a log as it grows?
tail -f
how to show specific column of text on an output?
cut -c 0-5 (will show only first 5 letter of each line, -d = choose a delimiter)
how to append each lines of file2 to the matching line of file1?
paste file1 file2
join does the same thing as paste, but remove reducdant words, keeping only 1
what are the 3 modes of vim, and how to switch between them?
- Command = vim starts and open in command mode, ESC = go back to command mode
- Insert = to type, i = go to insert mode
- LastLine = also called ‘ex’ mode, : = takes you to last line mode
Vim controls for: secondary keys for left, down, up, right. move forward 1 page and move backward 1 page?
- h,j,k,l = secondary keys for left, down, up, right
- CTRL+F = move forward 1 page
- CTRL+B = move backward 1 page
Vim controls for: undo, undo all changes since last file save, quit without saving, write and quit
• u = undo once
• :e! = undo all changes since last file save
• :q! = quit without saving
• :wq! = write and quit
* command ending with ! just mean to force that command, sometimes is necessary
Vim controls for: delete caracter at cursor, delete current line, delete single word at cursor, open a new line below and start insert mode from there
- x : delete single caracter at cursor
- dd : delete current line
- dw : delete single word at cursor
- o : open a new line below, and start insert mode from there
Vim controls for: searching and replacing, pretty much the same as with ‘sed’.
\:s/bob/BOB/ = replace the first instance of bob for BOB in current line \:s/bob/BOB/g = replace all instances of bob for BOB in current line \:%s/bob/BOB/g = replace all instances of bob for BOB in the whole file
Vim controls for: find that word forward and backward in the text
- /word = find that word forward in the text (from cursor position)
- ?word = find that word backward in the text (also from cursor position)
In the TUUUGGGOOO file permission scheme (each rwx is a permission trio), what are the different types (T) possible?:
- = normal file l = sym link b = block device c = caracter device d = directory
What is the analogy and thing to be careful of with folder permissions? :
Think of folders permissions as a room, read is a window to the room, and execute is the door to the room. write = if a user has write permission in a directory, he can add and delete every files in that directory (Warning!).
Is chmod recursive by default? :
No, it need to use -R for that.
Whats SUID, and how to add it? :
(Set User ID) = allows a user to run a program as if he was the owner of that program (often that owner is root). To set, user Octal method and add a 4 in front (ex : chmod 4777 file, OR chmod u+s)
Whats SGID, and how to add it? :
(Set Group ID) = When set of a directory, the permission automatically gives group ownership of all new files created in the directory to the group owner of the directory. To set, user Octal method and add a 4 in front (chmod 2XXX, OR chmod g+s)
Whats a stick bit, and how to add it?
Prevent non owners or non-root from deleting files in a directory (chmod 1XXX)
how to show ACL permissions of a file, and set it :
• getfacl file1 = show permissions of a file
• setfacl -m u:bob:rw file1 = set access list on a file. -m is to modify the acl.
*u=user g=group m=mask
*make sure the package name “acl” is installed first
*setfacl -m m::rx file1 = remove read and execute from the ACL Mask
How to see and change the default permissions of a created file? :
- with Maximum default value - Umask
* Maximum default value is : files it is set at : rw-rw-rw- and folders it is set at : rwxrwxrwx
how to put limits on what a user can do? :
ulimit
how to change the owner or group owner of a file or folder? :
chown user:group file (-R = make it recursive).
* For only changing the group, the chgrp command exists too.
Command to set password security limits to users?:
chage [username] (-l to see current settings.)
What does the different UID range mean?:
0 = Root 1 = bin user, responsible for some system binaries and nonlogin accounts. 99 = the nobody account. mainly used for anonymous access on ftp and http servers, and sometimes NFS from root 1-499 = service accounts 500+ = standard accounts.
Difference between “su - [username]” and “su [username]”? :
- su - (or -l) = switch user and shell
* su = just change user to root but dosent change the shell [less recommended]
Best way to edit the /etc/sudoer file without risking errors and conflicts? :
visudo
How to set Mandatory Access Control? (MAC) :
Use SELinux. SELinux “locks down” processes, diminishing potential damages from a compromised process.
*Whenever MAC is activated, both DAC and MAC will overlap. Usually MAC controls are evaluated first, and if the access is granted, then the file permissions are granted.
How to show current SELinux mode and set it :
getinforce, and setinforce [#]. (1 to put SELinux in enforcing mode, 2 for permissive mode which only logs but never block.)
How does the SELinux policy work? :
SELinux is a collection of rules that determine what restrictions are imposed by the policy. each rule is a boolean. getbool will show rules of the policy. setsebool will set it.
How to see a file or process SELinux context? :
with -Z. (ps -Z for processes, ls -Z for files and folders.)
Whats another MAC system that plays a role very similar to SELinux? less used than SELinux, but SUSE use it. :
AppArmor. control of apparmor is done with commands like aa-status, or aa-disable, etc..
Whats the 3 types of compressions that can be used with a TAR archive, and whats the option letter? :
- gunzip = .tar.gzip = lowest compression = most frequent = z
- bunzip2 = .tar.bz2 = medium compression = j
- unxz = .tar.xz = highest compression = use more memory, newer = J
Whats the format and order to writing a TAR command? :
- tar –>2. c,t,x (create, list, expand) —>3. v (verbose) —>4. z, j, J (gunzip, bzip, xz) —>5. f (filename) —> [files or folders to compress]
* EX : tar -cvzf tecmint-14-09-12.tar /home/tecmint/
How to zip and unzip a file (instead of tar) :
- zip endfile.zip file1 file2 file3
* unzip [filename.zip]
“copy in/out” command? :
cpio
How to create backup images of cds and dvd in a ISO format? :
with the “dd” command. ( dd if=[origin] of=[destination] )
how to compress and expand files?:
use short version of the command for compress, and long for expand! ex: gzip and gunzip.
bunzip and bzip.
unxz and xz
Some account can be remote, and that means they wont show up in the /etc/passwd and /etc/shadow. How to find them? :
getent passwd [user] getent look at the nsswitch (network share switch) file to know where to look for remote accounts, at /etc/nsswitch.conf
How are user entries in /etc/passwd formatted (ross:x:500:100:Ross Brunson:/home/ross:/bin/bash) ? :
what are /etc/securetty and /etc/usertty files?
specifies from where the root is allowed to log in, and how users are allowed to log in (for systems that dont use PAM..)
where is a user primary group and secondary group(s) assigned? :
• Primary groups : defined in the /etc/passwd
• Secondary groups : if a user appear in the /etc/group entry of a group, the user is a member of that group.
* /etc/group = group equivalent of /etc/passwd