├── LICENSE
├── README.md
├── command_bk
└── template.py
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Muhammad Ismail Zam Zam
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CentOS/Red-Hat-Command-Cheatsheet
2 |
3 | The below list are not covering all the commands for Linux Administration. These are commands that are not oftenly used but would be needed extermely in hours of matter of troubleshooting. This list is limited but can be improved much more.
4 |
5 | Redhat Package Manager (RPM)
6 |
7 |
8 | ```bash
9 | #Check RPM signature
10 | rpm --checksig <.rpm pkg>
11 | ```
12 | ```bash
13 | #Install RPM package
14 | rpm -ivh <.rpm pkg>
15 | ```
16 | ```bash
17 | #Check dependencies of RPM pkg
18 | rpm -qpR <.rpm pkg>
19 | ```
20 | ```bash
21 | #Install RPM pkg without dependencies
22 | rpm -ivh --nodeps <.rpm pkg>
23 | ```
24 | ```bash
25 | #List all files of installed RPM packages
26 | rpm -ql <.rpm pkg>
27 | ```
28 | ```bash
29 | #List installed RPM packages
30 | rpm -qa
31 | ```
32 | ```bash
33 | #List installed RPM packages
34 | rpm -q <.rpm pkg>
35 | ```
36 | ```bash
37 | #List all recently installed RPM packages
38 | rpm -qa --last
39 | ```
40 | ```bash
41 | #Upgrade a RPM package
42 | rpm -Uvh <.rpm pkg>
43 | ```
44 | ```bash
45 | #Remove RPM package
46 | rpm -evvnx <.rpm pkg>
47 | ```
48 | ```bash
49 | #Remove RPM package without dependencies
50 | rpm -ev --nodeps
51 | ```
52 | ```bash
53 | #Query a file that belongs which RPM package
54 | rpm -qf /usr/bin/htpasswd
55 | ```
56 | ```bash
57 | #Show the information of installed RPM package
58 | rpm -qi vsftpd
59 | ```
60 | ```bash
61 | #Show the information of RPM package before install
62 | rpm -qip <.rpm pkg>
63 | ```
64 | ```bash
65 | #Show documentation of instal RPM package
66 | rpm -qdf /usr/bin/vmstat
67 | ```
68 | ```bash
69 | #Verifying a package compares information of installed files against rpm db
70 | rpm -Vp <.rpm pkg>
71 | ```
72 | ```bash
73 | #Verifying all packages
74 | rpm -Va
75 | ```
76 |
77 |
78 |
79 | YUM (Yellowdog Updater and Modifier)
80 |
81 |
82 | ```bash
83 | yum upgrade
84 |
85 | ```
86 | ```bash
87 | yum localinsatll
88 |
89 | ```
90 | ```bash
91 | yum remove
92 |
93 | ```
94 | ```bash
95 | #install/update/upgrade or transaction history
96 | yum history list
97 |
98 | ```
99 | ```bash
100 | yum history list all
101 |
102 | ```
103 | ```bash
104 | #pkg info install/update/upgrade or transaction history by id
105 | yum history info
106 |
107 | ```
108 | ```bash
109 | #undo the transaction by id
110 | yum history undo
111 |
112 | ```
113 | ```bash
114 | #redo the transaction by id
115 | yum history redo
116 |
117 | ```
118 | ```bash
119 | #yum stores transaction in single SQLite db. To start new transaction history
120 | yum history new
121 |
122 | ```
123 | ```bash
124 | yum whatprovides
125 |
126 | ```
127 | ```bash
128 | yum --showduplicates list httpd | expand
129 |
130 | ```
131 | ```bash
132 | yum list available java*
133 |
134 | ```
135 | ```bash
136 | yum list installed
137 |
138 | ```
139 |
140 |
141 |
142 |
143 | Permission
144 |
145 |
146 | ```bash
147 | #set suid bit such as -rwSr-xr-x. capital S means (rws)
148 | chmod 4655
149 |
150 | ```
151 | ```bash
152 | #Setgid on dir, all dir/files in it will get same ownership as parent dir. It doesn't matter who is creating
153 | ```
154 | ```bash
155 | #setting setgid bit
156 | chmod g+s
157 | ```
158 | ```bash
159 | #setting sticky bit such as drwxrwxrwt. small t means (rwxt)
160 | chmod 1777
161 | ```
162 | ```bash
163 | #setting sticky bit such as drwxrwxrwT. capital T means (rwt)
164 | chmod 1776
165 | ```
166 | ```bash
167 | #asssigning recursive permission of all files/dir in target dir
168 | chown -R :
169 | ```
170 |
171 |
172 |
173 |
174 | User Administration
175 |
176 |
177 | ```bash
178 | useradd -g itadmin -c "DB User" -u 1135 -s "/bin/sh" -d /home/techguy1
179 | #In the above command, we are creating the new user with custom options as simple "#useradd " will create with default setting. The -g (group) -c (description) -u (user id) -s (which shell to be assigned) -d (landed home dir)
180 | ```
181 | ```bash
182 | useradd -g -G # assign the user primary and secondary group
183 |
184 | ```
185 | ```bash
186 | passwd -l #locking password of user
187 |
188 | ```
189 | ```bash
190 | passwd -u #unlocking password of user
191 |
192 | ```
193 | ```bash
194 | passwd -e #expire password
195 |
196 | ```
197 | ```bash
198 | echo 'myPassword123' | sudo passwd --stdin
199 |
200 | ```
201 | ```bash
202 | passwd -x -1 #Turnoff password expiry
203 |
204 | ```
205 | ```bash
206 | usermod -L #locking user
207 |
208 | ```
209 | ```bash
210 | usermod -U #unlocking user
211 |
212 | ```
213 | ```bash
214 | chage #set password expiry
215 |
216 | ```
217 |
218 |
219 |
220 |
221 |
222 | Access Control Lists (ACLs)
223 |
224 |
225 | ```bash
226 | setfacl -m u:priya:rw #assiging the a new user 'priya' with read/write permission on the file. -m (modifying) -u (user)
227 | ```
228 | ```bash
229 | setfacl -m mask:r #setting mask on file
230 | ```
231 | ```bash
232 | setfacl -d -m u:priya:rw #setting ACL for directory
233 | ```
234 | ```bash
235 | getfacl -R > permissions.acl #BackUp ACL's in file having all info related ownership/dir inside the dir,subdir,files
236 | ```
237 | ```bash
238 | setfacl --restore=permissions.acl #Restore the Permissions/Ownership
239 | ```
240 |
241 |
242 |
243 |
244 |
245 | Crontab
246 |
247 |
248 | ```bash
249 | crontab -l #show crontab for all users
250 | ```
251 | ```bash
252 | crontab -u -l #show crontab for specific user
253 | ```
254 | ```bash
255 | crontab -e #add cron entry in crontab file
256 | ```
257 |
258 |
259 |
260 |
261 |
262 | Process
263 |
264 |
265 | ```bash
266 | ps -a #all terminal
267 | ```
268 | ```bash
269 | ps -e #list of all the processes
270 | ```
271 | ```bash
272 | ps -o #customer properties
273 |
274 | ```
275 | ```bash
276 | ps -ao tty,comm,pid,%mem,%cpu # & #run the task in background
277 |
278 | ```
279 | ```bash
280 | ps -fp $(pgrep -d, -x logrotate)
281 |
282 | ```
283 | ```bash
284 | pgrep -u unison
285 |
286 | ```
287 | ```bash
288 | ps -p -o etime #process execution time
289 |
290 | ```
291 | ```bash
292 | ps -eo user,pid,ppid,%mem,%cpu --sort=-%cpu | head
293 |
294 | ```
295 | ```bash
296 | ps lax
297 |
298 | ```
299 | ```bash
300 | ps fax
301 |
302 | ```
303 |
304 |
305 |
306 |
307 |
308 |
309 | Network
310 |
311 |
312 |
313 | ```bash
314 | dig +trace www.google.com
315 |
316 | ```
317 | ```bash
318 | nmcli dev status
319 |
320 | ```
321 | ```bash
322 | nmcli con del
323 |
324 | ```
325 | ```bash
326 | ip addr show
327 |
328 | ```
329 | ```bash
330 | nmcli con show
331 |
332 | ```
333 | ```bash
334 | nmcli con add con-name type ifname ip4 gw4
335 |
336 | ```
337 | ```bash
338 | nmcli con up
339 |
340 | ```
341 | ```bash
342 | nmcli con mod ipv4.gateway
343 |
344 | ```
345 | ```bash
346 | hostnamectl set-hostname
347 |
348 | ```
349 | ```bash
350 | netstat -rn
351 |
352 | ```
353 | ```bash
354 | route -n
355 |
356 | ```
357 | ```bash
358 | tcpdump -i
359 |
360 | ```
361 | ```bash
362 | tcpdump -i host -nn
363 |
364 | ```
365 | ```bash
366 | tcpdump -i -s 0 -w
387 |
388 |
389 |
390 | Memory
391 |
392 |
393 |
394 | ```bash
395 | egrep --color 'Mem|Cache|Swap' /proc/meminfo | awk '{print $1 " " $2/1000/1000 "GB"}' #show information in GB
396 |
397 | ```
398 | ```bash
399 | smem -s swap -t -k -n -r
400 |
401 | ```
402 | ```bash
403 | smem -u -p -r
404 |
405 | ```
406 | ```bash
407 | free -h
408 |
409 | ```
410 |
411 |
412 |
413 |
414 |
415 | Disk
416 |
417 |
418 | ```bash
419 | df -h
420 |
421 | ```
422 | ```bash
423 | df -Th
424 |
425 | ```
426 | ```bash
427 | du -sh
428 |
429 | ```
430 | ```bash
431 | df --local -P #in KBs
432 | ```
433 | ```bash
434 | du -sch .[!.]* * | grep --regex="[0-9]*G"
435 |
436 | ```
437 | ```bash
438 | lsof -u #list of openfiles by specific user
439 |
440 | ```
441 | ```bash
442 | lsof | grep delete #list of openfiles that are deleted
443 |
444 | ```
445 | ```bash
446 | lsof | awk '{print $1}' | sort | uniq -c | sort -r -n #sort number of open files by process
447 |
448 | ```
449 |
450 |
451 |
452 |
453 |
454 | SFTP/SCP
455 |
456 |
457 | ```bash
458 | sftp -oPort= @
459 |
460 | ```
461 | ```bash
462 | sftp -oPort= -oIdentityFile= @
463 |
464 | ```
465 | ```bash
466 | sftp -o KexAlgorithms= -o HostKeyAlgorithms= -oIdentityFile= -oPort= @
467 |
468 | ```
469 | ```bash
470 | sftp -oPort= -o KexAlgorithms=diffie-hellman-group14-sha1 -o HostKeyAlgorithms=+ssh-dss -oIdentityfile= @
471 |
472 | ```
473 | ```bash
474 | scp -P @: #send the file to target system
475 |
476 | ```
477 | ```bash
478 | scp -P @: #fetch/download file from the target system
479 |
480 | ```
481 |
482 | ```bash
483 | scp -r /path/to/local/source user@ssh.example.com:/path/to/remote/destination #send dir from the target system
484 |
485 | ```
486 |
487 | ```bash
488 | scp -r user@ssh.example.com:/path/to/remote/source /path/to/local/destination #fetch/download dirctory from the target system
489 |
490 | ```
491 |
492 |
493 |
494 |
495 |
496 | Bolt
497 |
498 |
499 | For the --tmpdir flag we can use the home directory path of the remote user which will logged in on the behalf of the bolt. At some time /tmp is not executable due to which the command gets failed. (~mizz - will be confirm)
500 |
501 | ```bash
502 | bolt command run "" --no-host-key-check --tmpdir=/tmp -p --tty --targets @ -u
503 |
504 | ```
505 | ```bash
506 | bolt command run "" --no-host-key-check --tmpdir=/tmp -p --tty --targets -u
507 |
508 | ```
509 | ```bash
510 | bolt script run