CTRL+L clears terminal ////////
~$ sudo xxx (act as root user for 1 command) /////
### SSH ////
~$ ssh
[email protected] (IP)
no characters will appear when typing password
### echo////
echo (outputs provided text)_ USEFUL FOR DEBUGGING
~$ echo "hello friend"
-dont need quotes if no spaces in text
### whoami////
woami (find who is logged in rn)
~$ whoami
## FILE SYSTEM NAV ////
### ls -- LISTING
-shows directories & folders
-you list contents of directory without navigating to it by using ~$ ls [foldername] eg pictures
-a shows even hidden files (.)
--help
### cd -- change directory
-~$ cd pictures
-swap to a directory
~$ cd .. (go up a folder)
### cat -- concatenate
-output contents of files
-use cat to output contents without navigating to it
~$ cat /home/ubuntu/documents/todo.txt
### pwd -- print working directory (present)
-full path to current working directory
## SEARCHING FOR FILES /////
### find -- search for files (far better then windows search)
super simple use or very complex
find -name passwords.txt
find a name of that file in current directory
wildcard (*)
find -name *.txt
finds everyfile in current directory with .txt extension
### GREP
search the contents of files for specific values
E.G. access log
~$ grep "THM*" access.log
## INTERACTION WITH FILE SYSTEM ////
touch - create file -- ~$ touch note
mkdir (make directory) create a folder -- ~$ mkdir library
cp (copy) copy a file or folder -- ~$ cp note note2
mv (move) move a file or folder, rename, or merge -- ~$ mv note2 ./Documents
rm (remove) remove a file or folder use -R with it to remove a folder --- ~$ rm -R library
file (file) determine the type of a file -- ~$ file note
## SHELL OPERATORS///
"&" allows you to run commands in the background of your terminal
copy large file and do other stuff in terminal
"&&" allows you to combine multiple commands together in one line of your terminal
command1 && command2 -- however command2 will only run if command1 was successful
">" redirector - take the output from a command (such as cat to output a file) and direct it somewhere else
E.G. redirect the output of echo into a text file with given name ~$ echo hey > welcome
IF FILE "WELCOME" exists, that contents will be overwritten
">>" same as ">" but appends the output rather then replacing (nothing is overwritten)
same usage as ">" however adds to bottom of written file instead of overwitting
~$ echo trychackme >> passwords "adds tryhackme to passwords file"
useful for logging information
## PERMISSIONS -- read, write, execute
~$ ls -l (shows files and permissions)
-rwxrwxrwx
12 3 4
1)file type:
- indicates regular file
d indicates directory
4)Read, write, and execute permissions for all other users
3)Read, write, and executew permissions for the group owner of the file
2)Read, write , and execute permission for the file owner
### SWITCHING BETWEEN USERS ////
~$ su (substitute user) -l switch is like a regular environment of that specific user
## COMMON DIRECTORIES ///
/etc - etc folder is common to store system files used by OS
/var - variable data, stores requently accessed data or written by apps running
/root - home for the root system user
/tmp - temporary, volatile data, will only be used once or twice. data is cleared out when comp is restarted
## TERMINAL TEXT EDITORS
~$ nano myfile
use commands at bottom with ctrl key
VIM IS FAR MORE ADVANCED, really good for code. Pretty much always installed
## DOWNLOADING FILES///
wget, allows getting files over web via HTTP. downloads to current directory
~$ wget htmladdress
## TRANSFERRING FILES FROM LOCAL VIA SSH ///
WHAT YOU NEED to xfer from local machine to remote machine
IP of remote system (192.168.1.30)
user on remote (david)
name of file on local system (important.txt)
name that you want to store the file as on system (transferred.txt)
~$ scp important.txt
[email protected]:/home/david/transferred.txt
REMOTE TO LOCAL
~$ scp
[email protected]:/home/david/transferred.txt notes.txt
## SHARING FILES FROM YOUR HOST WITH WEB ///
can be downloaded from another computer with commands such as curl and wget. must know the exact name and location of the file you want
ON HOST: ~$ python3 -m http.server
downloader: ~$ wget http://192.168.9.100:8000/filename
## PROCESSES///
each program has its own id (PID)
~$ ps
to see processes run by other users like system processes
~$ ps aux
system statistics
~$ top or htop (colored)
### KILL A COMMAND
~$ kill processPID
SIGTERM - allow to do some cleanup before killed
SIGKILL - dont allow any cleanup
SIGSTOP - stop/suspend a processes
namespaces - sections of computing power, can only see within
### GETTING PROCESSES/SERVICES TO START ON BOOT
systemctl -- command allows us to interact with the systemd process.
~$ systemctl [option] apache2
options:
Start, stop, enable(onboot), disable(onboot)
### BACKGROUND AND FOREGROUNDING
ctrl + z a script to background a process
~$ fg -- bring back into foreground
## AUTOMATION ///
cron processes, interacted with the use of crontabs
crontab is a special file with formatting that is recognised by cron. they require 6 specific values:
MIN - Whbat minute to execute at
HOUR - what hour to execute at
DOM - what day of the month to execute at
MON - what month of the year to execute at
DOW - what day of week to execute at
CMD - the actual command that will be executed
example update cmnatic's documents every 12 hrs.
~$ 0 *12 * * * cp -R /home/cmnatic/documents /var/backups/
@reboot
CRONTAB GENERATOR, CRON GURU
crontabs can be edited with crontab-e
## PACKAGE MANAGEMENT///
software is submitted to an "apt" repository. you can add community rep by using ~$ add-apt-repo
~$ dpkg (package installers) // using apt means that whenever we update our system, the repo that owns software will also be checked for updates
GPG (Gnu Privacy Guard) keys assure good quality of files, safety check
~$ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
~$ apt install sublime-text
~$ apt remove sublime-text
## LOGS ////
rotating (os autmatically managing logs)
access logs and error logs
~$ cd /var/log