Difference between revisions of "IT-OS-Admin-Linux"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Basics)
(Files)
Line 46: Line 46:
 
/etc/environment # Configuration of Entviroment
 
/etc/environment # Configuration of Entviroment
 
/etc/hosts
 
/etc/hosts
...
+
-----------------------------------------------------------------------------------------------------
 
/etc/fstab # Configuration of Disks
 
/etc/fstab # Configuration of Disks
 
/etc/mtab # Configuration of Mount Devices
 
/etc/mtab # Configuration of Mount Devices
Line 57: Line 57:
 
/etc/fonts/fonts.conf         # Font-Configurations
 
/etc/fonts/fonts.conf         # Font-Configurations
 
/etc/fonts/local.conf         # Font-Configurations
 
/etc/fonts/local.conf         # Font-Configurations
..
+
-----------------------------------------------------------------------------------------------------
 
/usr/share/fonts/ # Users Fonts
 
/usr/share/fonts/ # Users Fonts
 
/usr/share/themes/ # Users Themes
 
/usr/share/themes/ # Users Themes
... # ..
+
-----------------------------------------------------------------------------------------------------
 
~/.fonts.conf.d         #
 
~/.fonts.conf.d         #
 
~/.fonts.conf #
 
~/.fonts.conf #
...
+
-----------------------------------------------------------------------------------------------------
 
~/.bashrc # Shell-Config
 
~/.bashrc # Shell-Config
 
~/.bash_profile         #
 
~/.bash_profile         #

Revision as of 00:17, 1 March 2021

Source

Folders & Files

Folders

/boot    >>Contains boot loader related files.
/bin     >>Contains binary executables.
/sbin    >>Contains administrator binary executables, just like /bin.
/lib     >>Contains 32bit libraries essential for binaries  in /bin and /sbin
/lib64   >>Contains 32bit libraries essential for binaries  in /bin and /sbin
---
/dev     >>Contains device files.
/etc     >>Contains configuration files required by all programs.
/opt     >>Contains add-on applications from individual vendors.
/usr     >>Contains binaries, libraries and source for second level programs.
---
/root    >>Home directory for the root user.
/home    >>Home directories for all users to store their personal files.
---
/mnt     >>Temporary mount directory where sysadmins can mount filesystems.
/media   >>Temporary mount directory for removable devices.
---
/proc    >>Contains information about system process.
/run     >>Run-time variable data
/srv     >>Contains server specific services related data.
/sys     >>Contains information about the devices connected to the computer.
/var     >>Contains files that are expected to grow.
/tmp     >>Contains temporary files created by system and users.

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

Top Commands

whoiam    # Current user
man       # Help
pwd       # Present working Directory
ls        # List File/Directory
cd        # Change Directory
cp        # Copy
mv        # Move
rm        # Remove
mkdir     # Create Directory
---
cal; date # Calender; Current Date & Time
---
df        # Report disk space usage
du        # Report file space usage
lsblk     # List block devices
fdisk     # manipulate disk partition table
---
cat
less
tail
find
diff
---
vi; nano
toch     # Create File
grep     # print lines matching a pattern
awk      # print column matching a pattern
sed      # Substitute, replace test
---
free     # RAM allocation
lscpu    # CPU Info
top
ps
history
shutdown
reboot
---
<command> & # Start command in Background
exit
kill     # kill -9 $PID;
crontab  # crontab -e; crontab -l
---
if <command>; then <command> fi
for x in {1..10}; do <command>; done
while:; do <command>; done
until false; do <command>; done
---
ctrl+a; ctrl+e; ctrl+d; ctrl+c; ctrl+z; ctrl+r
ctrl+alt+f1 # New tty Session
ctrl+alt+t  # New Termina

Basics

$ find . -name testfile.txt           # Find a file called testfile.txt in current and sub-directories
$ mv $SOURCE $TARGET                  # move folder
$ rm -rf $Folder_Name                 # remove directories force & recursively
---------------------------------------------------------------------------------------------
$ 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
---------------------------------------------------------------------------------------------
$ ls /usr/javalib/*.jar               # All the .jar files in current directory.
$ ls /usr/javalib/**.jar              # All the .jar files in current directory and subdirectories.
---------------------------------------------------------------------------------------------
$ sudo tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz
$ echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
$ source /etc/profile
or
$ echo "export PATH=$PATH:/usr/local/go/bin" >> $HOME/.profile
$ source $HOME/.profile

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

CronJob

* * * * * auszuführender Befehl
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── Wochentag (0-7, Sonntag ist 0 oder 7)
│ │ │ └────── Monat (1-12)
│ │ └──────── Tag (1-31)
│ └────────── Stunde (0-23)
└──────────── Minute (0-59)

CMD-HowTo

# Rename all file names from uppercase to lowercase
for i in $( ls | grep [A-Z] ); do mv -i $i `echo $i | tr 'A-Z' 'a-z'`; done

Shell

-d file			# True if file is a directory.
-e file			# True if file exists.
-f file			# True if file exists and is a regular file.
-L file			# True if file is a symbolic link.
-r file			# True if file is a file readable by you.
-w file			# True if file is a file writable by you.
-x file			# True if file is a file executable by you.
file1 -nt file2		# True if file1 is newer than (according to modification time) file2
file1 -ot file2		# True if file1 is older than file2
-z string			# True if string is empty.
-n string			# True if string is not empty.
string1 = string2		# True if string1 equals string2.
string1 != string2		# True if string1 does not equal string2.

Don't leave a blank variable, unset it if it was empty
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
export OS_PROJECT_NAME="demo"
unset OS_USER_DOMAIN_NAME
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

Network

arp -a
nmap -sP 192.168.1.0/24
sudo mount -t cifs -o username=user,password=pin //172.29.32.184/sharename /media/Data/

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

  • sudo dpkg -i filename.deb
  • sudo rpm -i filename.rpm

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