linux [Docs]

User Tools

Site Tools


linux

Summary of "Cert Prep: LPI Linux Essentials (010-160)"

https://www.linkedin.com/learning/cert-prep-lpi-linux-essentials-010-160/

General

  • 96% servers use Linux
  • Open source: code avialable for public use or modification, distribution under a license.
  • Licenses: 45% of github is MIT
  • Distribution: kernel + config + libraries + programs
  • OS differences: market share pcs (77 windows, 18 macOs, 2 linux)
  • Package installs and repositories: each distro has its package manager (.deb, .rpm(red hat, fedora, openSUSE). tar(universal, arch linux))
  • Package manager: deb (dpkg, apt-get, apt), rpm (rpm, yum, dnf)

CLI

  • Shell: program that takes commands form the keyboard and gives them to the kernel to execute
  • Bash: type of shell (there are alternatives like zsh)
  • Terminal: Gui window to access to shell
  • \ : scapes chars. echo "I have \$1200"
  • FHS: Filesystem Hierarchy Standard defines the directory structure and directory contents in Linux distributions. It is maintained by the Linux Foundation.

  • Character names:

    • / : lash
    • - : dash
    • ~ : tilde
  • Commands: ls, pwd, mv, rm, mkdir, touch, locale, hostname, date, uptime, df

  • ls -l(permission, ownership, size)a(show hidden)
  • wildcard: characters of regexp: ? * []

    • ls -la b[ao][wl]??.txt
  • Hard Link vs Symbolic Link

    • hardlink: duplicate directory entry where both entries point to the same file
    • symbolic link: a file that refers to another file by name. ln -s originame linkname

miro.medium.com_max_1174_1_hsizugggbk8-vrdfvp3ujw.jpeg

Piping

https://linuxhint.com/linux_pipe_command/

https://ryanstutorials.net/linuxtutorial/piping.php

https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_07

Every single program in the UNIX/Linux system has 3 built-in data streams.

  • STDIN (0): Standard input
  • STDOUT (1): Standard output
  • STDERR (2): Standard error

pipe redirection (|): send data from a program to another. file redirection (>): sends or gets data to/from a file

  • | : stdout to stdin
  • |& (shorthand for 2>&1): stderr and stdout to stdin
  • > : redirects to a file, overwrittes it
  • \2> : redirects errors to a file, overwrittes it
  • \&> : redirects errors to a file, overwrittes it
  • >> : redirects to a file, appends content
  • < : redirects from a file
    user@bash: wc -l < myoutput
    8
  • <>:
    user@bash: wc -l < barry.txt > myoutput
    user@bash: cat myoutput
    7
  • 2> : redirects errors
    user@bash: ls -l video.mpg blah.foo 2> errors.txt
  • 2>&1: errors redirected to the stdouput (&1) redirect errors to stdout and then redirect everyting to a file. When Bash sees several redirections it processes them from left to right.
    ls asdf.txt > myoutput 2>&1 

    the 2>&1 output goes to myoutput

https://stackoverflow.com/a/40319372/1034806

-command > output is just a shortcut for command 1> output

Scripts

#! (is a script) /... (program executed)

#!/bin/bash
#!/bin/bash
 
# variables:
# $ip=....
 
# conditional expressions
# if [ -s filename ]
 
filename=$1  
if  [  -f  "$filename"  ]; then  
echo  "File exists"  
else  
echo  "File does not exist"  
fi

execute it:

./asdfasdf.sh

Processes

https://www.tecmint.com/linux-process-management/

  • Foreground processes (interactive processes) – these are initialized and controlled through a terminal session.
  • Background processes (non-interactive/automatic processes) – are processes not connected to a terminal; they don’t expect any user input.
  • Daemons: A program that runs as a "background" process (without a terminal or user interface), commonly waiting for events to occur and offering services.
  • The Init Process (/sbin/init): The parent of all processes on the system, it’s the first program that is executed when the Linux system boots up.
  • pid (process id), ppid (parent pid), ps, top (interactive updating view of ps), free (check free ram)
  • Kernel ring buffer (/var/log/dmesg) : is stored on memory (dmesg). A ring buffer is a special kind of buffer that is always a constant size, removing the oldest messages when new messages come in.

Networking

  • DNS (Domain Name System) (Internet phonebook)
  • DHCP (Dynamic Host Configuration Protocol): Is a network management protocol used on Internet Protocol networks whereby a DHCP server dynamically assigns an IP address and other network configuration parameters to each device on a network so they can communicate with other IP networks.
  • Ehernet: Is a family of computer networking technologies commonly used in local area networks (LAN), metropolitan (MAN), wide (WAN).
  • Hostname: The name the computer gets
  • Netmask (Subnet mask): Divide the net on subnets. The masks determines all the subnet parameters.
  • Gateway: A gateway is a network node that serves as an access point to another network. A default gateway is the node in a computer network using the internet protocol suite that serves as the forwarding host (router) to other networks when no other route specification matches the destination IP address of a packet
  • TCP/IP : set of standards that underlie most modern network connections at the sw level
  • ip address ⇒ netmask ⇒ ip address(router) ⇒ ip address (dns server)

www.homenethowto.com_wp-content_uploads_dns-via-home-router2.jpg

Programs

  • traceroute (track problems in connection)
  • test dns: host, dig, nslookup
  • netstat

Security

  1. shut down servers
  2. enable a firewall
  3. use good passwords
  4. keep sw up to date

User accounts and groups

/etc/passwd

whoami

id

adduser

useradd

usermod and groupmod to manage users and groups

who: who is logged in the system

var/log/auth.log : all info about users

Ownerships and permissions

permissions for user, group and others

chown

chgrp

umask

sticky bit

suid

sgid

linux.txt · Last modified: 2020/07/02 16:06 (external edit)