Browse Source

Create lsysadmin.md

Thomas Kandler 7 years ago
parent
commit
81b4ac6df4
1 changed files with 122 additions and 0 deletions
  1. 122
    0
      lsysadmin.md

+ 122
- 0
lsysadmin.md View File

@@ -0,0 +1,122 @@
1
+# Linux SysAdmin Notes
2
+
3
+These notes were written with some prior knowledge of Linux and therefore may just represent individual knowledge gaps.
4
+
5
+## Basics terminal
6
+
7
+`pwd` - print working directory  
8
+`rmdir` - remove dir (empty)  
9
+`man program` - manual  
10
+`ls -s` - symbolic link  
11
+`head` - first 10 lines of file (default)  
12
+`tail` - last 10 lines of file (default)  
13
+`tail -f /var/log/dmesg` - follow the ende of the file (useful for logs)  
14
+`poweroff` -- `init 0 / init 6` - shutdown / restart  
15
+`cp` - copy  
16
+`cd ../../..` - go up 3 directories  
17
+`ls -lh` - long list human readable  
18
+`sudo -i` - interactive root session  
19
+`wc -l` - count stuff  
20
+`df -h` - list mounted devices (human readable)  
21
+`cut -d: -f2` - take some (piped) input, look for delimiter ":", take stuff from second field; so `Key1: Value1` will return `Value1` 
22
+`sort -bf` - sort by first letter  
23
+`uniq` - print only unique  
24
+`wc` - word count  
25
+`grep` - searching, finding, filtering (powerful, [learn more](http://www.panix.com/~elflord/unix/grep.html))
26
+`which` - shows the full path of (shell) commands
27
+`whereis` - where is a command (binary, source, manual)
28
+`locate` - find files by name  
29
+`cat /etc/network/interfaces` - list network devices/interfaces
30
+
31
+## Pipes and Redirection
32
+
33
+`|` - pipe character  
34
+`echo "hello world" > hello.txt` - write things to file; truncates before writing  
35
+`echo "hello world" >> hello.txt` - appends output  
36
+there are three channels: 0 - Standard Input (STDIN), 1 - Standard Output (STDOUT) and 2 - Standard Error (STDERR)   
37
+to catch STDERR --> `2>` (channel two), e.g. `ls -lh someNoneExistingFile.txt 2> action.log`  
38
+input redirection: `mail -s "this is a test" thomas < message.txt`  
39
+`ps | less` - show all processes and pipe it into the program `less` which shows big texts in way which is easy to navigate  
40
+
41
+`&&` - check if left command is successful, then execute the right command  
42
+`ls file.txt && echo "Success."` > Success  
43
+`ls wrongfile.tct` && echo "Success." > Error  
44
+
45
+
46
+## vi basics
47
+
48
+`:wq!` - write, quit, don't prompt me
49
+
50
+## Package management
51
+
52
+`apt-cache search ...` - search for package (Ubuntu/Debian)  
53
+`apt-get remove ...` - remove package  
54
+`apt-get autoremove` - clean up unneeded packages  
55
+
56
+## Processes 
57
+
58
+`ps aux | grep "process name"` - get info about process  
59
+`kill PID` - kill process (SIGTERM = 15) with specified PID  
60
+`pkill -u USERNAME` - kill process of user   
61
+`nice -n 15 program` - start a program with low priority (19 = lowest; -20 highest)  
62
+`renice -5 PID` - change niceness of process  
63
+`/proc` - directory of all processes which is managed by the kernel and holds all the information about processes
64
+
65
+## Filesystem 
66
+
67
+`man hier` - man page on filesystem hierarchy (overview on filesystem)  
68
+`udevd` - device daemon
69
+
70
+__Places__
71
+
72
+* `/bin` - binaries for applications
73
+* `/boot` - boot images
74
+* `/dev` - devices
75
+* `/etc` - configuration data for applications
76
+* `/home`
77
+* `/lib` / `/lib64` - shared libraries 
78
+* `/mnt` - mount
79
+* `/proc` - process directory (informations about running processes)
80
+* `/opt` - optional software, no clear convention using this
81
+* `/sbin` - system binaries
82
+* `/tmp` - temporary files, cleaned on restart
83
+* `/usr` - non-essential binaries
84
+* `/var/log` - system logs
85
+
86
+absolute and relative paths: `/home/user/downloads` and `downloads/`
87
+
88
+__Filetypes (with flag/first bit on `ls -l`)__
89
+
90
+Regular file (`-`)
91
+Directory (`d`)  
92
+Character Device (`c`)  
93
+Block Device (`b`)  
94
+Local Domain Socket (`s`)  
95
+Named Pipe (`p`)  
96
+Symbolic Link (`l`)  
97
+
98
+__File permissions__
99
+
100
+`rwx` `rw-` `r--` - `owner read/write/execute` `group read/write` `anyone read`  
101
+
102
+`chmod 777` - `rwx` for owner, group, anyone  
103
+`chmod 666` - `rw-` for owner, group, anyone  
104
+`chmod 444` - `r--` for owner, group, anyone   
105
+`chmod 000` - `---` for owner, group, anyone 
106
+
107
+## LXC (LinuX Containers)
108
+
109
+when operating with LXC one should be root; even basic stuff like `lxc-ls` will need root privileges  
110
+
111
+`/var/cache/lxc/distro` - contains the cached images needed for creation of a LXC  
112
+`/var/lib/lxc/` - contains files for every created container (including rootfs)  
113
+`/var/lib/lxc/myfirstcontainer/config` - config _file_ (see `man 5 lxc.container.conf` 
114
+
115
+`lxc-create -t ubuntu -n myfirstcontainer` - type = ubuntu, name = myfirstcontainer; note: type takes host system defaults if not otherwise specified regarding architecture and what not; note further: will do a net install which is stored  
116
+`lxc-ls --fancy` - list running machines  
117
+`lxc-start -n myfirstcontainer -d` - start LXC in daemon mode; doesn't hog up the current shell session, starts in background; connect via SSH to IPV4  
118
+`lxc-stop -n myfirstcontainer -k` - stop plus kill  
119
+`lxc-freeze -n myfirstcontainer` - freezes the proccess  
120
+`lxc-attach -n myfirstcontainer` - attaches current shell to container (avoiding to SSH in) 
121
+
122
+