├── Links.txt ├── NFS_Server_Installation.txt ├── README.md ├── Troubleshooting_ext4.sh ├── configuring_remote_logging.txt ├── create_local_repo.txt ├── file_directory_permissions_cheatsheet.txt ├── linux_command_cheatsheet.md ├── linux_file_system_attributes.txt ├── repairing_ext4_superblock.txt └── vim_cheatsheet.md /Links.txt: -------------------------------------------------------------------------------- 1 | YouTube Playlist Linux on Azure: 2 | https://youtube.com/playlist?list=PLi0MTIjZai_yi1NkwNt4YBN3mdGSlG6TS 3 | -------------------------------------------------------------------------------- /NFS_Server_Installation.txt: -------------------------------------------------------------------------------- 1 | Network File System (NFS) Server Installation 2 | --------------------------------------------- 3 | 4 | sudo yum install nfs-utils 5 | 6 | sudo systemctl status nfs-server 7 | 8 | sudo vim /etc/exports 9 | /data *(ro) 10 | /files *(rw,no_root_squash) 11 | 12 | sudo mkdir /data 13 | sudo mkdir /files 14 | 15 | cd /data 16 | 17 | touch file1 18 | touch file2 19 | 20 | cd /files 21 | 22 | touch file23 23 | touch file24 24 | 25 | cd 26 | 27 | ls -ldZ /data /files 28 | 29 | sudo semanage fcontext -a -t public_content_rw_t "/data(/.*)?" 30 | sudo semanage fcontext -a -t public_content_rw_t "/files(/.*)?" 31 | 32 | ls -ldZ /data /files 33 | 34 | sudo restorecon -Rv /data 35 | 36 | sudo restorecon -Rv /files 37 | 38 | sudo systemctl enable nfs-server 39 | sudo systemctl start nfs-server 40 | sudo systemctl status nfs-server 41 | 42 | sudo firewall-cmd --list-all 43 | sudo firewall-cmd --get-services 44 | sudo find / -name *.xml | grep nfs 45 | sudo firewall-cmd --permanent --add-service=nfs 46 | sudo firewall-cmd --reload 47 | 48 | showmount -e localhost 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Linux command line for beginners! 2 | Everything about the Linux command line (With a focus on redhat based distributions)! 3 | -------------------------------------------------------------------------------- /Troubleshooting_ext4.sh: -------------------------------------------------------------------------------- 1 | #Let's assume that there is a file system error at /dev/sdb2 2 | 3 | lsblk 4 | 5 | dump2fs /dev/sde2 | grep uperblock #(everything is ok with /dev/sde2 - I write "uperblock" because I don't know if it's upper or lower case) 6 | 7 | dump2fs /dev/sdb2 | grep uperblock 8 | 9 | fsck /dev/sdb2 #(We could try to repair the partition directly => BUT, we are looking for the superblocks) 10 | 11 | mkfs.ext4 -n /dev/sdb2 #(ATTENTION: be sure to use -n!!!!) => now we see the superblocks 12 | 13 | fsck -b 40961 /dev/sdb2 #(after -b insert a superblock from above) 14 | 15 | fsck /dev/sdb2 16 | -------------------------------------------------------------------------------- /configuring_remote_logging.txt: -------------------------------------------------------------------------------- 1 | Configuring Remote Logging on a RedHat based system 2 | --------------------------------------------------- 3 | 4 | Jounald and rsyslog work together by "house". We can check this in the following config file: 5 | 6 | sudo vim /etc/system/journald.conf 7 | 8 | #ForwardToSyslog=yes 9 | 10 | #=> Now we configure remote logging 11 | 12 | SRV01: 13 | ------ 14 | 15 | sudo vim /etc/rsyslog.conf 16 | 17 | => remove hashtag 18 | $ModLoad imtcp 19 | $InputTCPServerRun 514 20 | 21 | sudo systemctl restart rsyslogd 22 | 23 | sudo firewall-cmd --add-port=514/tcp 24 | sudo firewall-cmd --add-port=514/tcp --permanent 25 | 26 | 27 | SRV02 (this server sends the logs to SRV01): 28 | 29 | sudo vim /etc/rsyslog.conf 30 | 31 | *.* @@srv01.prime.pri:514 (two @@ means TCP one @ means UDP) 32 | 33 | sudo systemctl restart rsyslogd 34 | -------------------------------------------------------------------------------- /create_local_repo.txt: -------------------------------------------------------------------------------- 1 | Create local Repo on a RedHat based Linux! 2 | ------------------------------------------ 3 | 4 | In order to install software on a server that is offline, we set up a local repo. 5 | The only thing it needs is the operating system installation .iso file. 6 | 7 | sudo mkdir /ISOs 8 | 9 | sudo cp /home/tom/Downloads/RHEL7.iso /ISOs 10 | 11 | sudo mkdir -p /var/OSimage 12 | 13 | sudo mount -o loop,ro /ISOs/RHEL7.iso /var/OSimage 14 | 15 | sudo vim /etc/yum.repos.d/rhel7.repo 16 | [RHEL7] 17 | name=RHEL 7 18 | baseurl=file:///var/OSimage/ 19 | gpgcheck=0 20 | enabled=1 21 | 22 | sudo yum clean all 23 | 24 | yum repolist 25 | -------------------------------------------------------------------------------- /file_directory_permissions_cheatsheet.txt: -------------------------------------------------------------------------------- 1 | 000 = --- = 0 2 | 001 = --x = 1 3 | 010 = -w- = 2 4 | 011 = -wx = 3 5 | 100 = r-- = 4 6 | 101 = r-x = 5 7 | 110 = rw- = 6 8 | 111 = rwx = 7 9 | 10 | Now let's explain the columns with permissions. 11 | 12 | drwxr-xr-x 2 tom tom 4096 Jan 2 09:23 Images 13 | -rw-r--r-- 1 tom tom 25 Jan 5 14:29 File2 14 | 15 | The first bit (-) stands for a file or the (d) stands for a folder. There are others for example (l) for link. Even more examples: 16 | 17 | - -> file 18 | c -> character device 19 | d -> directory 20 | l -> symbolic link 21 | s -> Unix socket 22 | b -> block device 23 | p -> pipeline 24 | 25 | The permissions consist of 12 bits. We have here 9 bits for the permissions. The first 3 are for the owner, the next 3 for the group and the last 3 for the "world/others". 26 | 27 | d|rwx|r-x|r-x| 2 tom tom 4096 Jan 2 09:23 Images 28 | 29 | r stands for read 30 | w stands for write 31 | x is for execute (for a file, this would be for example an executable script - to execute a script needs r-x) 32 | x stands for execute (for a directory, this means that you can change into the directory - because open/execute folder) 33 | 34 | 12-9 results in 3, which means there are 3 bits left. These 3 bits are used for special permissions, namely for SUID, SGID and Sticky Bit. 35 | -------------------------------------------------------------------------------- /linux_command_cheatsheet.md: -------------------------------------------------------------------------------- 1 | ### Not in alphabetical order! 2 | 3 | | Command | Arguments | Description | 4 | | :--- | :---: | :--- | 5 | | cd | | Change the directory | 6 | | pwd | | Output of the current working path | 7 | | ls | | List a folder content | 8 | | ls | -l | Long Listing | 9 | | ls | -a | Displays everything even hidden files | 10 | | cat | | Shows the contents of a file or merges files | 11 | | less | | Displays the contents of a file page by page (With additional functions like the search) | 12 | | more | | Displays the contents of a file page by page | 13 | | stat | | Display file or file system status | 14 | | hostnamectl | | Can be used to query and change the system's computer name and associated settings | 15 | | date | | Displays the date and time | 16 | | cal | | Displays the calendar | 17 | | lsusb | | Displays the USB devices | 18 | | lscpu | | Displays information about the CPU architecture | 19 | | lspci | | Detailed information about the PCI devices and buses in the system | 20 | | lsblk | | Lists information about all available or the specified block devices | 21 | | df | | Report file system disk space usage | 22 | | df | -hT | Disk space allocation with (-h) "human readable" numbers and (-T) file system | 23 | | uptime | | Incl. CPU utilization 1min, 5min and 15min | 24 | | uptime | -p | -p stands for "pretty" | 25 | | uname | | Displays the OS | 26 | | uname | -a | -a for all info | 27 | | touch | | Update the access and modification times of each file to the current time. If the file does not exist, one will be created | 28 | | rm | | Remove files or directories | 29 | | rm | -i * | * means delete all files, with -i prompt before every removal | 30 | | rm | -f | -f is for force, execute the command either way | 31 | | rm | -r | Remove directories and their contents recursively | 32 | | rm | -v | -v is for verbose, explain what is being done | 33 | | mkdir | | Create the Directory(ies), if they do not already exist | 34 | | rmdir | | Remove empty (must be empty) directories => if not use rm -rf | 35 | | cp | | Copy files and directories | 36 | | cp | -R | -r copy directories recursively | 37 | | mv | | Move (or rename) files | 38 | | ln | | Create symbolic and hard links | 39 | | ln | -s | Make symbolic links instead of hard links | 40 | | echo | | Display a line of text | 41 | | paste | | Merge lines of files | 42 | | join | | Join lines of two files on a common field | 43 | | expand | | Convert tabs to spaces | 44 | | unexpand | | Convert spaces to tabs | 45 | | sed | | Stream editor for filtering and transforming text (Syntax example: sed 's/this/through-this/g' file.txt) | 46 | | | | s stands for substitute, g stands for global=all | 47 | | wc | | Print newline, word, and byte counts for each file | 48 | | wc | -l | -l Print the newline counts (-l is an l stands for lines) | 49 | | chmod | | Change file mode bits | 50 | | chmod | ugo+x␣filename | Set the execute bit for user, group and other for a file | 51 | | chmod | 755␣filename | rwx the user, r-x for the group and r-x for others on a file | 52 | | chgrp | | Change group ownership | 53 | | useradd | | Create a new user or update default new user information (mostly used with RedHat based distros) | 54 | | useradd | -ms (for example) | -m Create the user's home directory if it does not exist. -s The name of the user's login shell. | 55 | | adduser | | Create a new user or update default new user information (mostly used with Debian based distros) | 56 | | usermod | | Modify a user account | 57 | | usermod | -aG | -a Add/Append the user to the supplementary group(s). -G A list of supplementary groups which the user is also a member of.| 58 | | userdel | | Delete a user account and related files | 59 | | userdel | -f | -f This option forces the removal of the user account, even if the user is still logged in. It also forces userdel to remove the user's home directory and mail spool, even if another user uses the same home directory or if the mail spool is not owned by the specified user | 60 | | groupadd | | Create a new group | 61 | | groupmod | | Modify a group definition on the system | 62 | | groupdel | | Delete a group | 63 | | grep | | Search a file for a pattern | 64 | | grep | -i␣pattern␣file | -i Perform pattern matching in searches without regard to case 65 | | tail | | Print the last 10 lines of each File to standard output | 66 | | head | | Print the first 10 lines of each File to standard output | 67 | | cut | | Print selected parts of lines from each File to standard output | 68 | | sort | | Write sorted concatenation of all Files(s) to standard output | 69 | | du | | Summarize disk usage of the set of files, recursively for directories | 70 | | du | -sch | -s display only a total for each argument, -c produce a grand total, -h print sizes in human readable format (e.g., 1K 234M 2G) | 71 | -------------------------------------------------------------------------------- /linux_file_system_attributes.txt: -------------------------------------------------------------------------------- 1 | File Attributes 2 | --------------- 3 | 4 | 1. Using any method you choose, create a directory in your home directory called 'attributes'. Once created, change to that directory. 5 | 6 | [user@centos:~] $ mkdir attributes && cd attributes 7 | 8 | 2. Create three files in this directory called 'test1', 'test2' and 'test3'. The contents of the files can be anything you choose. 9 | 10 | [user@centos:attributes/] $ touch test1 test2 test3 11 | 12 | or 13 | 14 | [user@centos:attributes/] $ echo "Some text" > test1 (repeating for test2 and test3) 15 | 16 | 3. Using the appropriate octal or ascii permission notation, change permissions to be read, write, execute for the owner and read, execute for everyone else. 17 | Be sure to apply those permissions to all three files. 18 | 19 | [user@centos:attributes/] $ chmod 755 test* 20 | 21 | or 22 | 23 | [user@centos:attributes/] $ chmod a+rw test* && chmod u+rwx test* 24 | 25 | 4. On 'test1', leave the permissions as set in Step 3. On 'test2', using the appropriate elevated access and special attributes for files, set the file so that, 26 | regardless of ownership, the file cannot be overwritten but CAN be appended to. On 'test3', using the special attributes for files, set the file to be immutable 27 | regardless of permissions or ownership. 28 | 29 | [user@centos:attributes/] $ sudo chattr +a test2 30 | [user@centos:attributes/] $ sudo chattr +i test3 31 | 32 | 5. Before you go further, list the file attributes (not permissions/ownership) and verify the proper attributes are applied as expected. Using the echo command and 33 | output redirection, attempt to overwrite the contents each of the three files and note the results. 34 | 35 | [user@centos:attributes/] $ lsattr 36 | ----i--------e-- ./test3 37 | -------------e-- ./test1 38 | -----a-------e-- ./test2 39 | [user@centos:attributes/] $ echo "Overwrite" > test1 40 | [user@centos:attributes/] $ echo "Overwrite" > test2 41 | bash: test2: Operation not permitted 42 | [user@centos:attributes/] $ echo "Overwrite" > test3 43 | bash: test3: Permission denied 44 | 45 | 6. Attempt to delete 'test1', 'test2' and 'test3'. If the deletion fails for any of the files, set the appropriate special attribute that will allow the deletion to 46 | succeed and verify. 47 | 48 | [user@centos:attributes/] $ rm test1 49 | [user@centos:attributes/] $ rm test2 50 | rm: cannot remove ‘test2’: Operation not permitted 51 | [user@centos:attributes/] $ rm test3 52 | rm: remove write-protected regular empty file ‘test3’? y 53 | rm: cannot remove ‘test3’: Operation not permitted 54 | [user@centos:attributes/] $ sudo chattr -a test2 && sudo chattr -i test3 55 | [user@centos:attributes/] $ rm test2 56 | [user@centos:attributes/] $ rm test3 57 | -------------------------------------------------------------------------------- /repairing_ext4_superblock.txt: -------------------------------------------------------------------------------- 1 | If you want to do this on a test partition, use the following command (note: substitute the path to your test partition). 2 | 3 | sudo dd if=/dev/urandom of=/dev/sdb2 bs=1k seek=10 count=4k 4 | 5 | Now we list all block devices (it needs elevated rights for this): 6 | 7 | sudo lsblk 8 | 9 | sudo dump2fs /dev/sde2 | grep uperblock (I write "uperblock" because I don't know if it's upper or lower case ;-) 10 | 11 | sudo fsck /dev/sdb2 (We could try to repair the partition directly => BUT, we are looking for the superblocks) 12 | 13 | sudo mkfs.ext4 -n /dev/sdb2 (ATTENTION: be sure to use -n!!!! without -n you create a new file system!!) => now we see the superblocks 14 | 15 | sudo fsck -b 40961 /dev/sdb2 (after -b insert a superblock from above) 16 | 17 | If the first superblock does not work use the next one. 18 | 19 | sudo fsck /dev/sdb2 20 | -------------------------------------------------------------------------------- /vim_cheatsheet.md: -------------------------------------------------------------------------------- 1 | # The vim cheatsheet 2 | 3 | **How do I get into the editor mode now?** 4 | 5 | (i) for 'insert', this immediately switches vim to insert mode 6 | (I) moves the cursor to the beginning of the line and enters insert mode 7 | (a) insert (append) after the cursor 8 | (A) moves the cursor to the end of the line and enters insert mode 9 | (o) inserts a new line below the current line and enters insert mode on the new line 10 | (O) inserts a new line above the current one and enters insert mode on the new line 11 | 12 | **Exit and save:** 13 | 14 | :w filename saves the file under filename. If the file already exists the specification of the file name is optional 15 | :w! saves the file even if it is read-only, if possible 16 | :wq saves the current file and exits the editor 17 | :x saves the current file and exits the editor 18 | ZZ saves the current file and exits the editor. The missing colon is not a typo! 19 | :q terminates the editor. Edited files must have been saved before 20 | :q! terminates the vi even if files have not yet been saved. The changes to these files are lost 21 | 22 | **Navigation in a document:** 23 | 24 | The most important move commands are: 25 | 26 | h moves the cursor one character to the left 27 | j moves the cursor down one character 28 | k moves the cursor up one character 29 | l moves the cursor one character to the right 30 | G moves the cursor to the end of the file 31 | gg moves the cursor to the beginning of the file 32 | H moves the cursor to the top of the screen 33 | L moves the cursor to the bottom of the screen 34 | --------------------------------------------------------------------------------