### Run nmap from different installation paths Source: https://linuxupskillchallenge.org/17 This example shows how to execute the `nmap` utility by specifying its full path, demonstrating how the system resolves commands based on the PATH environment variable. It allows testing different versions of the same utility installed in separate locations. ```bash /usr/bin/nmap -V /usr/local/bin/nmap -V ``` -------------------------------- ### System Crontab Configuration Example Source: https://linuxupskillchallenge.org/10 This example shows the structure of the system-wide crontab file located at /etc/crontab. It includes comments explaining the time fields and demonstrates how to define cron jobs, specifying the user (e.g., 'root') that will execute the command. It also shows examples of hourly, daily, weekly, and monthly job execution. ```bash # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh # You can also override PATH, but by default, newer versions inherit it from the environment #PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) ``` -------------------------------- ### Install Software Packages with APT Source: https://linuxupskillchallenge.org/04?q= This command installs a specified package from the online repositories. It requires root privileges, hence the use of 'sudo'. The system will download and configure the package and its dependencies. ```bash sudo apt install mc ``` -------------------------------- ### Vim: Running Vim Tutor Source: https://linuxupskillchallenge.org/06 This command initiates the Vim tutorial, a guided exercise designed to teach the fundamentals of Vim. It's recommended for new users to build proficiency. ```bash vimtutor ``` -------------------------------- ### Install rsyslog Source: https://linuxupskillchallenge.org/08 Installs rsyslog to enable logging on minimal Ubuntu installations. This command ensures the availability of the `/var/log/auth.log` file, which is crucial for the lesson's examples. It addresses a common issue in minimal Ubuntu versions. ```Bash sudo apt install rsyslog ``` -------------------------------- ### Search for Software Packages with APT Source: https://linuxupskillchallenge.org/04?q= This command searches the online repositories for packages matching a given keyword. It's the first step before installing any new software on Debian-based systems like Ubuntu. The output lists available packages and their descriptions. ```bash apt search "midnight commander" ``` -------------------------------- ### Install UFW Firewall (Linux) Source: https://linuxupskillchallenge.org/09 Installs the Uncomplicated Firewall (UFW) utility on Ubuntu-based Linux systems. UFW provides a simpler interface for managing netfilter firewall rules compared to raw iptables commands. This command requires root privileges. ```bash sudo apt install ufw ``` -------------------------------- ### Launch Midnight Commander (mc) Source: https://linuxupskillchallenge.org/04?q= This command starts the Midnight Commander file manager. It provides a text-based interface for navigating the file system, copying, moving, and editing files. It's useful for exploring directories and viewing file contents. ```bash mc ``` -------------------------------- ### Install and Use 'at' for One-Shot Tasks (Ubuntu) Source: https://linuxupskillchallenge.org/10 This snippet demonstrates how to install the 'at' package on Ubuntu and schedule a one-time command to execute in the future. It shows how to pipe a command to 'at' and verifies the output. ```bash sudo apt update sudo apt install at vagrant@ubuntu2204:~$ tty /dev/pts/0 vagrant@ubuntu2204:~$ echo 'echo "Greetings $USER!" > /dev/pts/0' | at now + 1 minutes warning: commands will be executed using /bin/sh job 2 at Sun May 26 06:30:00 2024 ... vagrant@ubuntu2204:~$ Greetings vagrant! ``` -------------------------------- ### Getting Concise Command Help with `tldr` Source: https://linuxupskillchallenge.org/02 The `tldr` command provides simplified, example-driven explanations for commands, making it easier to quickly understand common use cases. It's useful when man pages are too verbose. ```bash $ tldr pwd pwd Print name of current/working directory.More information: https://www.gnu.org/software/coreutils/pwd. - Print the current directory: pwd - Print the current directory, and resolve all symlinks (i.e. show the "physical" path): pwd -P ``` -------------------------------- ### View APT Repository Sources Source: https://linuxupskillchallenge.org/04?q= This command uses Midnight Commander to view the contents of the Ubuntu sources list file. This file specifies the locations from which APT downloads packages, often including mirror sites. ```bash mc /etc/apt/sources.list.d/ubuntu.sources ``` -------------------------------- ### Cron Job Script Example for Daily Tasks Source: https://linuxupskillchallenge.org/10 This script, located in `/etc/cron.daily/dpkg`, is an example of a task that runs daily. It checks if systemd is running and exits if it is. Otherwise, it executes the `dpkg-db-backup` command. This illustrates how scripts in the `/etc/cron.daily` directory are executed automatically. ```bash #!/bin/sh # Skip if systemd is running. if [ -d /run/systemd/system ]; then exit 0 fi /usr/libexec/dpkg/dpkg-db-backup ``` -------------------------------- ### Getting Help for Shell Builtin Commands with `help` Source: https://linuxupskillchallenge.org/02 The `help` command is used to display information about shell builtin commands, which are commands implemented directly within the shell itself and may not have a corresponding man page. ```bash $ man export No manual entry for export $ help export export: export [-fn] [name[=value] ...] or export -p] Set export attribute for shell variables. Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied, assign VALUE before exporting. Options: -f refer to shell functions -n remove the export property from each NAME -p display a list of all exported variables and functions An argument of `--' disables further option processing. Exit Status: Returns success unless an invalid option is given or NAME is invalid. ``` -------------------------------- ### View File Hierarchy Manual Source: https://linuxupskillchallenge.org/04?q= This command displays the manual page for the 'hier' command, which explains the standard Linux directory structure. Understanding this hierarchy is crucial for system administration. ```bash man hier ``` -------------------------------- ### Update and Search File Index with updatedb and locate Source: https://linuxupskillchallenge.org/17 This snippet demonstrates how to update the file index using `sudo updatedb` and then search for specific files, such as 'bin/nmap', using the `locate` command. This is useful for finding files quickly, especially after manual installations. ```bash sudo updatedb locate bin/nmap ``` -------------------------------- ### Create a Compressed Home Directory Backup with Date Source: https://linuxupskillchallenge.org/10 This command manually creates a compressed tar archive of the /home directory, including the current date in the filename. It uses the date -I command to get the current date in ISO 8601 format, which is then embedded in the archive name. ```bash sudo tar -czvf /var/backups/home.$(date -I).tar.gz /home/ ``` -------------------------------- ### Basic Vim File Operations Source: https://linuxupskillchallenge.org/06 These commands demonstrate the initial steps for opening, copying, and editing a file using Vim. It covers navigating directories, copying files, and launching Vim for editing. ```bash cd pwd cp -v /etc/services testfile vim testfile ``` -------------------------------- ### Create and Manage Executable Scripts in Bash Source: https://linuxupskillchallenge.org/20 This section outlines the process of creating a script file named 'topattack' using vim, setting execute permissions with chmod, and moving it to the system's binary directory using mv. It's a fundamental workflow for deploying custom scripts. ```bash vim topattack chmod +x topattack mv topattack /usr/local/bin ``` -------------------------------- ### Create and Configure Admin User Account Source: https://linuxupskillchallenge.org/00-VPS-small Create a new user account and grant it administrative privileges. This involves adding the user to the 'admin' and 'sudo' groups, allowing them to execute commands with root privileges using the 'sudo' command. Replace 'snori74' with your desired username. ```shell adduser snori74 ``` ```shell usermod -a -G admin snori74 ``` ```shell usermod -a -G sudo snori74 ``` -------------------------------- ### Vim: Searching and Navigating File Source: https://linuxupskillchallenge.org/06 Illustrates how to navigate to the beginning ('gg') and end ('G') of a file, and how to search for text using the '/' command followed by the search term. The 'n' key is used to step through search results. ```vim G gg /sun n ``` -------------------------------- ### Upgrade Ubuntu Packages Source: https://linuxupskillchallenge.org/00-VPS-big Upgrades installed packages to their latest versions on an Ubuntu system. The '-y' flag automatically confirms any prompts. This command requires administrator privileges. ```bash sudo apt upgrade -y ``` -------------------------------- ### Get VM IP Address Source: https://linuxupskillchallenge.org/00-Local-Server This command is used to display network interface information, including the IP address assigned to the virtual machine. It is essential for establishing remote connections. ```bash ip address ``` -------------------------------- ### Searching for Commands by Keyword with `apropos` and `man -k` Source: https://linuxupskillchallenge.org/02 Both `apropos` and `man -k` allow you to search for commands based on keywords in their descriptions. This is helpful when you know what you want to do but not the exact command name. ```bash $ apropos "working directory" git-stash (1) - Stash the changes in a dirty working directory away pwd (1) - print name of current/working directory pwdx (1) - report current working directory of a process $ man -k "working directory" git-stash (1) - Stash the changes in a dirty working directory away pwd (1) - print name of current/working directory pwdx (1) - report current working directory of a process ``` -------------------------------- ### Bash Shebang Line Source: https://linuxupskillchallenge.org/20 The shebang line, starting with '#!', specifies the interpreter for the script. For bash scripts, it typically points to '/bin/bash'. This line is crucial for the system to execute the script correctly. ```bash #!/bin/bash ``` -------------------------------- ### Connect to Server via SSH with Private Key (Linux/macOS) Source: https://linuxupskillchallenge.org/00-Local-Server This command establishes an SSH connection to a remote server using a specific private key file. It's a more secure alternative to password authentication, especially when the private key is passphrase-protected. ```bash ssh -i private_key username@ip_address ``` -------------------------------- ### Vim: Saving Changes Source: https://linuxupskillchallenge.org/06 Demonstrates commands for saving changes to a file. ':w' writes the changes and stays in Vim, while ':wq' writes the changes and then quits the editor. ```vim :w :wq ``` -------------------------------- ### Enable UFW Firewall (Linux) Source: https://linuxupskillchallenge.org/09 Activates the Uncomplicated Firewall (UFW) on a Linux system, applying the configured rules. Once enabled, UFW starts enforcing the defined policies for incoming and outgoing network traffic. This command requires root privileges. ```bash sudo ufw enable ``` -------------------------------- ### Accessing Manual Pages with `man` Source: https://linuxupskillchallenge.org/02 The `man` command is used to display the manual page for a given command, providing detailed syntax and usage information. It's the primary tool for in-depth documentation. ```bash man pwd man cp man mv man grep man ls man man ``` -------------------------------- ### Exit Midnight Commander Source: https://linuxupskillchallenge.org/04?q= Pressing F10 within Midnight Commander exits the application. On some systems, like macOS Terminal, you might need to use ESC+0 as an alternative. ```bash F10 ``` -------------------------------- ### Understanding Crontab Syntax Source: https://linuxupskillchallenge.org/10 This snippet provides a clear breakdown of the standard crontab syntax, explaining each field (minute, hour, day of month, month, day of week) and the meaning of common operators like '*', ',', '-', and '/'. ```text * * * * * command to be executed - - - - - | | | | | | | | | ----- Day of week (0 - 7) (Sunday=0 or 7) | | | ------- Month (1 - 12) | | --------- Day of month (1 - 31) | ----------- Hour (0 - 23) ------------- Minute (0 - 59) ``` -------------------------------- ### Pipe and Filter with grep Source: https://linuxupskillchallenge.org/08 Piping allows the output of one command to be used as input for another. This example chains `cat` and `grep` to search for a specific string within a file. This is useful for combining commands to refine search results. ```Bash cat /var/log/auth.log | grep "authenticating" ``` -------------------------------- ### Filter with grep and cut Source: https://linuxupskillchallenge.org/08 This example combines `grep` and `cut` to extract specific fields from lines matching a pattern. The `cut` command is used to select specific columns based on a delimiter. This is useful for extracting structured data from text. ```Bash grep "authenticating" /var/log/auth.log| grep "root"| cut -f 10- -d" " ``` -------------------------------- ### Connect to Server via SSH (Linux/macOS) Source: https://linuxupskillchallenge.org/00-Local-Server This command initiates an SSH connection to a remote server using the provided username and IP address. It's the standard method for remote server management on Unix-like systems. ```bash ssh username@ip_address ``` -------------------------------- ### Invert Selection with grep -v Source: https://linuxupskillchallenge.org/08 The `-v` option inverts the `grep` selection, showing lines that do *not* match the given pattern. This is useful for excluding specific entries from the output. This example excludes lines containing "root". ```Bash grep "authenticating" /var/log/auth.log| grep -v "root"| cut -f 10- -d" " ```