To do this, we need parameters (for example)
server ip: 152.17.1.251 or ssh-server.example.com
port: 22 (Used for SSH)
password: password
If we have the Windows operating system using the program Putty, for Linux and MacOS built-in terminal
On Mac open Terminal program and enter in the command line
username@ssh-server.example.com
This command will connect to the SSH server on port 22, which is the default. To specify a different port, add -p to the end of the command to the port number you want to connect to, like this:
ssh username@ssh-server.example.com -p 2222
Next we need to enter our password to access the system if we use Terminal, and enter the password and user login if we connect via Putty
Login as:user password:password
The first commands that will be useful after logging in to the server
who 'shows which users are in the system' who | wc -1 'allows you to count users in the system'
The structure of the Linux team consists of the following components
(team) (keys) (arguments)
Keys are written with the sign –
which – shows the path to the program (example: which/ls)
Cntl + Z – allows you to run multiple tasks, fg – allows you to exit this mode
Ctrl + D – log in
apt-get update – update programs from the repository
apt-get install asterisk – install asterisk
ls 'will show a list of files in the current directory (does not display filenames that begin with . )' ls -a 'show all files' ls -a -l 'display information about files in long format (size, creation date, etc.)'
The keys can be swapped or combined
ls -al ls -al /etc/ 'will show all files in the etc directory' pwd 'home directory' date 'will display today's date' cal 'print a calendar' pwd .. 'parent directory' . 'urrent directory' u 'go out'
The quotes will leave the string unchanged. For example ‘*.html’
Tab complements commands
Files in linux
/bin – is the directory where the user files of the program are placed
/sbin – directory where system program files are placed
/var – directory where system program files are placed
/etc – configuration files
/lib – library files
Commands for working with the file system
ls ~user5 'see files in another directory' ls -a ~user5 'see all files in another directory' cd /etc/ 'opens a directory or file' cd(no arguments) 'opens the home directory' cd 'returns to the previous directory' vim /etc/skip.conf ^C 'open the file for editing' touch 'allows you to create a file if it does not exist' mkdir dir 'creates a directory' cp file1.txt dir1/ 'allows you to copy a file to a directory dir1' mv 'rename file (specify new name)' mv file1.txt dir1/file2.txt 'renaming the file we will give it a new directory' rmdir dir1 'allows you to delete the directory, but if it is empty' rm rfv dir1/ 'allows you to delete the directory along with the files' df 'allows you to estimate disk space' df -h 'disk space is clear to humans' du /usr/share/ - allows you to show how much disk space is occupied by directories du -sh /usr/share/ 'allows you to show how much disk space is occupied by directories (clear to humans)' du -s /usr/share/* | sort -n 'will display the size of the directory subdirectories and sort by the first column' find /usr/share -name index.html 'will find a file named index.html in the /usr/share directory' find /usr/share -name *.html 'will find all html documents in the /usr/share directory' :> /etc/asterisk/sip.conf 'delete the contents of the file instantly'
Commands for reading file contents
cat /etc/fstab 'display the contents of a small file' less /etc/fstab 'display the contents of a large file' tail /var/log/auth.log 'display last 10 lines of log file' tail -f /var/log/auth.log 'will display the log timeline in real time' tail -fn /var/log/auth.log 'output log files in real time, but only those that appeared after running the command'
Text editors ed sed vi vim
vim file2.txt 'run vim text editor' 'to enter text press I (insert)' esc :wq 'to save and exit' esc :q! 'exit without saving'
Command filters
cut -d: -f1 /etc/passwd 'allows you to cut on the separator' tr 'allows you to replace the characters with the selected character' cat /etc/passwd | tr ':' '-' 'replace characters : on -' sort /etc/services 'the command allows you to sort the data' sort -r /etc/services 'reverse sort' grep root /etc/passwd 'displays user information' grep bash /etc/passwd 'will exit all users from the bash shell'
Regular expressions
Recommended to take regular expressions in quotation marks
$ 'end of phrase' ^ 'the beginning of the phrase' grep bash$ /etc/passwd grep '^#' /etc/ssh/sshd_config 'will find in the file all lines that begin with the character #' grep -v '^#\|^$' /etc/ssh/sshd_config 'will find in the file all lines that do not begin with the # character and end immediately'
Processes in Linux
ps aux - outputs processes pstree - displays the process tree
Basic possibilities of interaction of processes in Linux
Each program has 3 file descriptors. The default 0 is connected to the keyboard. The file descriptor 1 is connected to the screen by default. Error messages are received in file descriptor 2
If we want to redistribute the keyboard we use the symbol “<”
If we want to redistribute the output to the screen, use the symbol “>”
If we want one program to pass output to another, we use a pipeline “|”
ps auxw>ps.txt 'stream redirection' cntrl + D (twice) 'ends streams' ps aux | grep init ls /binn 2> ls.err 'redirect to file descriptor 2'
Variables
env 'displays a list of environment variables' echo $LANG 'output the value of the variable' LANG = en_EN.UTF-8 'assign a new value to the LANG variable' f=file.txt 'assign the value of file.txt to the variable f' ls $f 'let's turn to the variable' LANG='' date 'It is possible to set individually for each program'
Completion codes
echo $? 'read the result of the program. 0 - mostly means successful' ip=8.8.8.8 ping -c1 -w1 $ip >/dev/null 2>&1 'make our program quiet' c1 -w1 $ip >/dev/null 2>&1 && echo OK 'if it is executed we will deduce OK' c1 -w1 $ip >/dev/null 2>&1 && echo notOK 'if it is not executed we will deduce notOK'
Signals
CNTRL + C 'allows you to stop the signal' kill -STOP 16244 'stop the signal with indicator 16244' kill -CONT 16244 'continue signal execution' kill -HUP 2615 service 'allows you to restart the process without using a signal'
Security systems and user rights
chown asterisk:asterisk /etc/asteriks/sip.conf 'change the group of owners' chmod /etc/asteriks/sip.conf 'change file permissions (access mask)' usermod -G sudo student 'grant sudo access rights'
Backup
cd /etc tar 'allows you to archive' tar -c 'creates an archive' tar -c -j 'creates and compresses the archive' tar -c -j /root/asterisk.tbz 'creates and compresses an archive to a directory' tar -c -v -j /root/asterisk.tbz 'creates and compresses the archive into a directory and shows what our program does'