Agenda: system-admin-exercises.txt

File system-admin-exercises.txt, 6.5 KB (added by admin, 7 years ago)
Line 
1Track 2 Workshop
2PacNOG 10
3
4System Administration
5---------------------
6
71. Reboot your system
8
9To restart your system, you could use:
10
11        $ sudo shutdown -r TIME
12
13... where time can be a day, hour, minute...
14
15Or you could try and reboot your machine *NOW*:
16
17        $ sudo shutdown -r now
18
19The "-r" means reboot.  Another command for doing this is "reboot".
20
21To stop a machine you can do:
22
23        # halt -p
24
25or
26
27        # shutdown -h -P now
28
29Be careful when using halt on remote systems!
30
31
322. Go to single user mode - DON'T ACTUALLY DO THIS, YOU WILL LOSE
33   Network conectivity to your machine!
34
35*IF* you wanted to go into single user mode, you could do:
36
37        $ sudo init 1
38
39This would take you down to single user mode.
40You can only log in as the root user, and only from the console.
41
42Some systems will require you to enter your password to access the
43shell.
44
45If you then wanted to go back to multi-user mode type:
46
47        # exit
48
493. Figure out how your machine has been partitioned
50
51You want to display free disk space, or "df":
52
53        $ df -h
54
55Use:
56
57        $ man df
58
59to understand what the "-h" option does.
60
61Look in /etc/fstab. This is where file systems are mounted in Linux. Read the
62man page on this file:
63
64        $ man fstab
65
66Notice that defined file systems are pointing to /dev/sda*. Have a look
67at these files:
68
69        $ ls -lah /dev/sda*
70        $ file /dev/sda*
71
72What type of files are these?
73
74
754. Create a new group
76
77In a terminal window first do:
78
79        $ sudo groupadd track2
80
81Now lets add some members to this group:
82
83        $ sudo vigr
84
85You will now be in the /etc/group file using the default EDITOR - vi or
86joe, or...
87
88Find the entry for "track2" - Easiest way is to press the "/" key, type
89"track2" and press <ENTER>
90
91        /track2         [press <ENTER>]
92
93You will be on this line:
94
95        track2:x:1002:
96
97Change the line to look like:
98
99        track2:x:1002:sysadm
100
101And save the file and quit.
102
103
104Verify that your sysadm user is now in the track2 group:
105
106        $ su - sysadm
107        $ groups
108
109
1105. Editing the command line revisited:
111
112We did this exercise in the introduction to Linux session. We will
113repeat it here.
114
115It is particularly useful to realize that you can edit a command just as
116you would a line of text in a file.
117
118For instance, you can:
119
120- Use your back-arrow and forward-arrow keys to change text in a command.
121  Use the Home and End keys to go to the start and the end of a command.
122
123Note: you do not need to go to the end of a command before pressing
124<ENTER> to execute the command. You can use the history command with
125grep to find a previous command.  For long commands this can save
126considerable time.
127
128You you can also use the reverse-search feature of bash:
129
1301.) Press ctrl-r
1312.) type the term you are searching for
1323.) Press ctrl-r to cycle through all occurrences of the term in your history
1334.) Press the right or left-arrow, HOME or END key to start editing the command.
134
135First, let's make sure we have a command to play with. Do the following command:
136
137        $ grep sysadm /etc/passwd
138
139Let's give some of these editing rules a try. Instead of searching for
140the sysadm user in the /etc/passwd file we'll search for the root user.
141
1421.) Press 'ctrl-r'
1432.) type sysadm
1443.) If necessary press ctrl-r again until you see the original command
145you used to search for the sysadm user in the /etc/password file
146("grep sysadm /etc/passwd").
147
1484.) Use the arrows keys to move in the command and change sysadm to root.
149You should now have the following on your command line:
150
151$ grep root /etc/passwd
152
153With your cursor positioned over just past the 't' in 'root', press
154<ENTER> to execute the command.
155
156You should see:
157
158root:x:0:0:root:/root:/bin/bash
159
160That's it. You can practice repeating the above with other parts of
161commands you have already executed
162
163(ls, grep, cat, etc.).
164
1655. Installing a package
166
167We're going to use the 'lsof' command in the next exercise, so let's install
168it:
169
170        $ sudo apt-get install lsof
171
1726. Using the pipe command
173
174Let's run a command with multiple lines of output:
175
176        $ sudo lsof -i
177
178Find the Process ID (PID) of one of the ssh server that is running on
179your machine:
180
181        COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
182        sshd        988 root    3u  IPv4   5040      0t0  TCP *:ssh (LISTEN)
183        sshd        988 root    4u  IPv6   5042      0t0  TCP *:ssh (LISTEN)
184
185Your PID will be different. Now let's look at all the associated files
186with this process:
187
188        $ sudo lsof -p PID
189
190        (replace PID with the number you got from the "lsof -i" command
191        above, for example 988 here)
192
193There are a fair number of files that are "open" by the ssh server, or
194daemon - the sshd command.
195
196Let's look at more interesting output from the prior command:
197
198        $ sudo lsof -p PID | grep REG
199
200Now let's see how many files the sshd program has open:
201
202        $ sudo lsof -p PID | grep REG | wc -l
203
204To see what these commands are doing read:
205
206        $ man lsof
207        $ man grep
208        $ man wc
209
210
2117. Use the top command
212
213The top command let's us see the status of our system at a quick
214glance. To use top simply do:
215
216        $ top
217
218The item at the top of list of running processes is the process using
219the most CPU resources.
220
221Open a new SSH connection to your PC. In that window type:
222
223        $ ls -lahR /
224
225Now in the other window where top is running you should start to see the "ls"
226process listed using some amount of your total CPU.
227
228At the top of the top window you'll see something like:
229
230        top - 08:10:23 up 16:14,  2 users,  load average: 0.00, 0.00, 0.00
231        Tasks:  91 total,   1 running,  90 sleeping,   0 stopped,   0 zombie
232        Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
233        Mem:   1016348k total,   568532k used,   447816k free,    91904k buffers
234        Swap:  2973688k total,        0k used,  2973688k free,   325908k cached
235
236This is a good, quick way to see how much RAM, Virtual memory, CPU,
237total running processes, etc. that your machine has, and is using.
238
239You can adjust the output of top as it is running. Exit from top by
240typing "q" and then do:
241
242        $ man top
243
244Now run top again and change what it is displaying interactively.
245
246All the information in top is part of a dynamic file system located in
247/proc. As an example do the following:
248
249        $ cd /proc
250        $ ls
251
252The numbered directories correspond to actual Process IDs of processes
253that are running. Look at the file meminfo:
254
255        $ less meminfo
256
257Note that it includes your total RAM. Top uses this file to get this
258information. Same for cpuinfo, loadavg, uptime, etc.
259
260If you want to know what command was executed to start a number process
261you can type (for instance):
262
263        $ less /proc/1/cmdline
264
265You'll see that the first process started on the system is init.
266
2678. A couple more useful tools
268
269        $ sudo apt-get install ifstat
270
271        $ ifstat
272
273... what does ifstat do ?
274
275        $ vmstat -a 1
276
277... what does vmstat do ?