IT-OS-Admin-Linux
Jump to navigation
Jump to search
Contents
Source
- Commands: https://ss64.com/bash/
- Commands: https://www.codecademy.com/learn/learn-the-command-line
- Commands: https://www.javatpoint.com/linux-tutorial
- Configurations: https://www.server-world.info/en/note?os=Fedora_32
- Docs: https://docs.fedoraproject.org/en-US/docs/
- RHEL-Trainig: https://www.redhat.com/en/services/training/rh024-red-hat-linux-technical-overview
- HowTo: https://www.howtoforge.com/
- Software-Flat: https://flathub.org/
- Software-Snap: https://snapcraft.io/
- News: https://vitux.com/
Folders & Files
/etc/bashrc /etc/profile /etc/environment # Configuration of Entviroment /etc/hosts ... /etc/fstab # Configuration of Disks /etc/mtab # Configuration of Mount Devices /etc/hostname # Where Hostname is saved /etc/init.d/ # Skripts that will be executed at system start up /etc/apt/sources.list.d # Ubuntu Reposotiery-Folder /etc/yum.repos.d/ # Fedora Reposotiery-Folder /etc/sysconfig/network-scripts/ifcfg-eth0 # Network-cfg /etc/fonts/conf.d /etc/fonts/fonts.conf # Font-Configurations /etc/fonts/local.conf # Font-Configurations .. /usr/share/fonts/ # Users Fonts /usr/share/themes/ # Users Themes ... # .. ~/.fonts.conf.d # ~/.fonts.conf # ... ~/.bashrc # Shell-Config ~/.bash_profile # ~/.bash_login # ~/.themes/ # Location of Themes ~/.icons/ # Location of Icons
Commands
Basics
$ find . -name testfile.txt # Find a file called testfile.txt in current and sub-directories $ mv $SOURCE $TARGET # move folder $ ln -s $SOURCE $LINK # create symbolic link $ ls -l $LINK # list symbolic link $ unlink $LINK # unlinke symbolic link
$ toch file.txt # create new empty file.exe $ echo "Hallo World" # Print out 'Hallo World' $ echo "Hallo World" > file.txt # To overwrite the content of file.txt $ echo "Hallo World" >> file.txt # To append to the end of file.txt $ cat file.txt # Print out the content of file.exe $ cat source.txt > file.txt # To overwrite the content of file.txt $ cat source.txt >> file.txt # To append to the end of file.txt
chmod & chown & chgrp
# USERS >> u:Owner, g:Group, o:Others, a:Everyone:[ugo] # OPERATION >> +:Add, -:Remove, =:Only # PERMISSIONS >> r:Read, w:Write, x:Execute
$ chmod $USERS $OPERATION $PERMISSIONS $FILE_NAME $ chmod uga+rwx -R $FILE_NAME $ chmod u=rwx,g=rwx,o=rwx $FILE_NAME $ chmod -R 0777 ./* # Everyone can do anything
$ chown $OWNER_NAME $FILE_NAME $ chgrp $GROUP_NAME $FILE_NAME
System
hostnamectl set-hostname new-name
Shell
timestamp=$(date +%Y%m%d%H%M%S)
nano ~/.bashrc # Auto start the agent
-----------------------------------------
if [[ "$(ps -u $USER | grep ssh-agent | wc -l)" -lt "1" ]]; then
ssh-agent -s >~/.ssh/ssh-agent
. ~/.ssh/ssh-agent >/dev/null
ssh-add ~/.ssh/id_rsa
else
. ~/.ssh/ssh-agent >/dev/null
fi
-----------------------------------------
User
sudo adduser –G [GROUP-ID] [USER-ID] # Add a new Group & User sudo deluser [USER-ID] # Delete User sudo remove [USER-ID] # Remove User ... echo "USER-ID ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers usermod -aG sudo [USER-ID] # Add User to Sudo-Group sudo visudo # Add “USER-ID ALL=(ALL:ALL) ALL” id ... su [USER-ID] # Change User in current Folder su - [USER-ID] # Change User in User Home-Folder sudo bash # Login as root sudo -i # Login as root sudo -i –u [USER-ID] # Login in account user passwd [USER-ID] # Change User Password gpasswd -a user-ID group-ID #
Locale & Keymap & Time
/etc/environment /etc/locale.conf ~/.config/locale.conf ... localectl localectl list-locales localectl set-locale LANG=en_US.UTF-8 ... localectl localectl list-keymaps localectl set-keymap de ... timedatectl timedatectl list-timezones timedatectl set-timezone Europe/Berlin
SSH
Settings
$ sudo dnf install openssh-client $ sudo dnf install openssh-server $ sudo systemctl restart sshd.service $ sudo systemctl enable sshd.service
- Key-Typs: RSA algorithm and DSA algorithm.
$ ~/.ssh/id_rsa.pvt # The file contains the RSA private key. $ ~/.ssh/id_rsa.pub # The file contains the RSA public key. $ ~/.ssh/authorized_keys # The file contains the keys that can be used for logging into system. ... $ chmod go-w ~/ $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys
sudo nano /etc/ssh/ssh_config sudo nano /etc/ssh/sshd_config ------------------------------ RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys PasswordAuthentication no # Yes: Can login with Password; No: Can’t login with Password ------------------------------ /etc/init.d/ssh restart
Generate Key
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "username@mail.com" # Generate prv and pub Key $ cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys $ chmod -R 600 ~/.ssh/id_rsa $ ssh -i ~/.ssh/id_rsa username@server.com # Login server with prv-key ... $ ssh-copy-id –i $PATH_PUBLIC_KEY $USERNAME@IP_ADDRESS # Copy Pub-Key to server $ cat ~/.ssh/id_rsa.pub | ssh user@hostname "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" $ ssh user@hostname "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/authorized_keys"
ssh-agent & ssh-add
$ vim ~/.ssh/config # Add key automatically to a running agent
-----------------------------------
AddKeysToAgent yes
## Home nas server ##
Host nas01
HostName 192.168.1.100
User root
IdentityFile ~/.ssh/nas01.key
Host github.com
IdentityFile ~/.ssh/github.key
-----------------------------------
$ eval $(ssh-agent -s) # Start the agent $ ssh-add ~/.ssh/id_rsa # Add the defualt key $ ssh-add -l # List keys $ ssh-add -d /home/user/.ssh/id_rsa # Remove key $ ssh-add -D # Remove all Keys $ eval $(ssh-agent -s -k) # Kill the agent $ ssh -T git@github.com $ ssh -T git@bitbucket.org
Firewall
Service
- cmd: status, start, stop, restart, reload, enable, disable
$ sudo systemctl status firewalld $ sudo systemctl status NetworkManager $ sudo systemctl status network ... sudo firewall-cmd --reload
Zone
sudo firewall-cmd --get-zones sudo firewall-cmd --get-active-zones sudo firewall-cmd --get-default-zone sudo firewall-cmd --get-services sudo firewall-cmd --list-all sudo firewall-cmd --list-ports
Zone-home
sudo firewall-cmd --zone=home --list-all sudo firewall-cmd --zone=home --list-ports sudo firewall-cmd --zone=home --list-services
Zone: Configuration
sudo firewall-cmd --set-default-zone=home sudo firewall-cmd --zone=home --change-interface=eth0 sudo firewall-cmd --zone=home --add-service=http sudo firewall-cmd --zone=home --add-port=80/tcp --permanent
New Zone "boxblue"
sudo firewall-cmd --permanent --new-zone=boxblue sudo firewall-cmd --permanent --zone=boxblue --add-service=ssh sudo firewall-cmd --permanent --zone=boxblue --add-service=http sudo firewall-cmd --permanent --zone=boxblue --add-service=https sudo firewall-cmd --permanent --zone=boxblue --add-service=samba sudo firewall-cmd --permanent --zone=boxblue --add-port=80/tcp sudo firewall-cmd --permanent --zone=boxblue --add-port=22/tcp sudo firewall-cmd --permanent --zone=boxblue --change-interface=wlp0s19f2u1 sudo firewall-cmd --permanent --set-default-zone=boxblue
Vim
Source: https://vim.rtorr.com/
Esc Exit the current mode. i Enter "Insert mode" for inserting text. v Enter "Visual mode" for character. V Enter "Visual mode" for line. : Enter "Command mode". ... h Move Left j Move Down k Move Up l Move Right ... ggVG Select hole text ... u Undo the last operation. d Delete or Cut selected item. y Copy line. p Paste storage buffer after the cursor. ... :q Quit Vim. :q! Quit Vim without saving the changes. :w Save the file :wq Save the file and quit Vim. :w $FILE_NAME Save the file with the filename "yx".
Package Manager
Ubuntu
- Location: /etc/apt/sources.list
fedora
- Location: /etc/yum.repos.d/
- DNF: Dandified YUM
sudo rpm –i filename.rpm ... dnf --version dnf history ... sudo ls /etc/yum.repos.d/ sudo dnf repolist sudo dnf repolist all sudo dnf config-manager --add-repo <repo-url> sudo dnf config-manager --set-enabled <repo-id> sudo dnf config-manager --set-disabled <repo-id> sudo dnf --enablerepo=<repo-id> sudo dnf --disablerepo=<repo-id> sudo dnf copr [enable|disable|remove|list|search] <parameters> ... sudo dnf list sudo dnf list installed sudo dnf list available sudo dnf check-update sudo dnf list updates ... sudo dnf update sudo dnf upgrade sudo dnf update vim sudo dnf search vim sudo dnf download vim sudo dnf install vim sudo dnf reinstall vim sudo dnf remove vim sudo dnf erase vim ... sudo dnf grouplist sudo dnf grouplist -v sudo dnf group info 'Development Tools' sudo dnf groupinstall 'Development Tools' sudo dnf groupupdate 'Development Tools' sudo dnf groupremove 'Development Tools' ... sudo dnf autoremove sudo dnf clean all
Samba
$ /etc/samba/smb.conf $ systemctl enable --now smb $ firewall-cmd --add-service=samba --permanent $ firewall-cmd --reload
Screen
screen -S <name> # start screen new screen -ls # list screen runing screen -r <name> # reattach to a session name .. Ctrl+a c # create window Ctrl+a n # next window Ctrl+a p # previous window Ctrl+a k # kill window Ctrl+a d # detach window
Desktop Environments
Links
Display Server (Xorg/Wayland)
loginctl # get session number from command output loginctl show-session 2 -p Type ... vi /etc/gdm/custom.conf vi /etc/gdm3/custom.conf ----------------------- WaylandEnable=false # To disable Wayland DefaultSession=gnome-xorg.desktop # To enable Xorg -----------------------
Sessions
ls -l /usr/share/xsessions/ # Lists installed desktop enviruments echo $XDG_CURRENT_DESKTOP
Display Manager: lightdm
- Install Display-Manager
- Install Greeter
- Setting Greeter
sudo dnf install lightdm # Display-Manager sudo dnf install elementary-greeter slick-greeter slick-greeter-cinnamon slick-greeter-mate # Greeter-Typs sudo dnf install lightdm-settings # For Settings ... ls /usr/share/lightdm/lightdm.conf.d/ # System-Settings ls /etc/lightdm/lightdm.conf.d/ # User-Settings lightdm --show-config ... [Seat:*] greeter-session=slick-greeter user-session=cinnamon