Setting up secure SSH server on Debian 9

adduser jonas
echo "jonas ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "AllowUsers jonas" >> /etc/ssh/sshd_config
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
sed -i 's/Port 22/Port 36478/g' /etc/ssh/sshd_config
ssh-copy-id jonas@remotehost
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
service ssh restart
sudo passwd -l root

Setup L2TP over IPsec VPN client on Ubuntu 18.04 using GNOME

Install network-manager-l2tp

sudo apt-get update
sudo apt-get install network-manager-l2tp
sudo apt-get install network-manager-l2tp-gnome

Set VPN properties via GUI

Navigate to Settings > Network > VPN > +

Select Layer 2 Tunneling protocol (L2TP)

Enter:
VPN Name, Gateway (domain name or IP),
User name,
NT Domain (in my case this is Active Directory domain name)

Choose IPsec settings,
check Enable IPsec tunnel to L2TP host,
enter your pre-shared key,
enter 3des-sha1-modp1024 as Phase1 Algorithms,
enter 3des-sha1 as Phase2 Algorithms

Set PPP options according to your VPN server configuration. Mine looks like this:

Last thing is to make sure your local network is L2TP pass-through and IPsec pass-through and thats it, ready to go!

File permissions and ownership

Listing files and permissions

ls -al                       # list files and display permissions
ll                           # list files and display permissions
stat -c '%A %a %n' *         # list files and display permissions in decimal
find . -printf "%m %p\n      # recursively list files and permissions in decimal
du -sh ./*                   # list directory contents with sizes in M, G

Setting permissions

chmod 755 dirname            # set directory permissions
chmod 644 filename           # set file permissions
find . -type d -exec chmod 755 {} \;  # recursively set directory permissions
find . -type f -exec chmod 644 {} \;  # recursively set file permissions
chmod u+w filename           # give owner permission to write to file
chmod g+w filename           # give group permission to write to file
chmod o+w filename           # give group permission to write to file
chmod a+w filename           # give everybody (u, g, o) permission to write to file
chmod g+x filename           # give group permission to execute file
chmod ugo+rwx filename       # give read write execute permissions to owner group others
chmod -R g+r directory       # recursively give directory read permission to group
chmod -R g-r directory       # recursively remove directory read permission from group
chmod -R g=r directory       # recursively set group permission only to read
chmod o-rwx file             # removes all permissions from others

Ownership

chown root filename          # change file owner to root
chown root dirname           # change directory owner to root
chown -R root dirname        # change directory owner to root recursively
chown root:user filename     # change file owner to root ant group to user
chown -R root:user dirname   # recursively change directory owner to root and group to user
chown :user filename         # set filename group to user
chgrp user filename          # set filename group to user
chgrp user dirname           # set dirname group to user
chgrp -R user dirname        # set dirname group to user recursively

chown -v -R root:user filename            # execute chown command and display results
chown --reference=file1 file2             # copy ownership properties from file1 to file2
chown --from=guest user filename          # set file owner to user if file is owned by guest
chown --from=:guest :user filename        # set file group to user if file belongs to group guest
chown --from=root:user user:root filename # set ownership to user:root if currently ownership is root:user

Search using find command

find -name apache.log                 # search for a file
find . -name apache.log               # search for a file
find . -type f -name apache.log       # search for a file
find . -type f -iname apache.log      # case insensitive search for a file
find -type d -name snap               # search for a directory
find . -type d -name snap             # search for a directory
find . -type d -iname snap            # case insensitive search for a directory
find . -type f -name '*.txt'          # search for txt files
find . -type f -perm 0644             # search for files with 0644 permissions
find . -type f ! -perm 0644           # search for files without 0644 permissions
find . -type f -perm 2644             # search for SGID files wifh 644 permissions
find . -type f -perm 1551             # search for sticky bit files with 551 permissions
find . -type f -perm /u=s             # search for SUID files
find . -type f -perm /g=s             # search for SGID files
find . -type f -perm /u=r             # search for read-only files
find . -type f -perm /a=x             # search for executable files
find . -type f -empty                 # find empty files
find . -type f -name '.*'             # find hidden files
find . -type f -user jonas            # find files whose owner is jonas
find . -type f -user jonas -name vi   # find file vi whose owner is jonas
find . -type f -group jonas           # find files whose group is jonas
find . -type f -group jonas -name vi  # find file vi whose group is jonas
find . -type f -mtime 10              # find files last modified within 10 days
find . -type f -atime 10              # find files last accessed within 10 days
find . -type f -mtime +3 -mtime -7    # find files last modified 3 and 7 days ago
find . -type f -cmin -10              # find files last changed within last 10 minutes
find . -type f -mmin -10              # find files last modified within last 10 minutes
find . -type f -amin -10              # find files last accessed within last 10 minutes
find . -type f -size 5M               # find files whose size is more than 5 MB
find . -type f -size +5M -size -10M   # find files whose size is between 5 and 10 MB

find . -size +10M -exec rm -rf {} \;                   # delete files whose size is greater than 10MB 
find . -type f -name *.jpg -size +2M -exec rm {} \;    # delete jpg files whose size is greater than 2 MB
find . -maxdepth 1 -type f -mtime +10                  # ignoring sub directories find all files last modified more than 10 days ago
find . -type f -exec grep -H 'text-to-find' {} \;      # find all files containing text
find . -type f -exec chmod 644 {} \;                   # recursively set 644 permissions to files
find . -type f -perm 0777 -print -exec chmod 644 {} \; # recursively set 644 permissions to files having 777 permissions
find . -type d -perm 777 -print -exec chmod 755 {} \;  # recursively set 755 permissions to directories having 777 permissions
find . -type f -name "vitests.txt" -exec rm -f {} \;   # find and delete delete file vitests.txt
find . -type f -name "*.jpg" -exec rm -f {} \;         # find and delete all jpg files 
find . -type f -exec grep -hrn "string" {} \;          # only display line contents containing string

SSH – connect to server using private and public key pair

Method #1

ssh-keygen -t rsa                      # Generate a private and public key pair
ssh-copy-id username@hostname          # Copy public key to remote host
ssh username@hostname                  # Connect to remote host using private key

# Optional - create an alias for whole connection string
echo 'alias aliasname="ssh username@hostname"' >> .bashrc
source ~/.bashrc

Method #2

ssh-copy-id -i ~/.ssh/id_rsa.pub username@hostname -p 55044
ssh -i ~/.ssh/id_rsa username@hostname -p 55044
echo 'alias aliasname="ssh -i ~/.ssh/id_rsa username@hostname -p 55044"' >> .bashrc
source ~/.bashrc

Using Vi

Navigating

h   # move left
l   # move right
k   # move up
j   # move down
w   # move to the next word
W   # move to next blank delimeted word
b   # move to the begining of the word
B   # move to the beginning of blank delimted word
e   # move to the end of the word
E   # move to the end of Blank delimited word
(   # move sentence back
)   # move sentence forward
{   # move paragraph back
}   # move paragraph forward
0   # move to the begining of the line
$   # move to the end of the line
gg  # move to the begining of the file
G   # move to the end of the file
nG  # move to nth line
:n  # move to nth line
fk  # move forward to letter k within current line
Fk  # move back to letter k within current line
H   # move to the top of the screen
M   # move to the middle of the screen
L   # move to the bottom of the screen

Inserting

i   # insert before cursor
I   # insert before line
a   # append after cursor
A   # append after line
cw  # change word
C   # change to the end of line
cc  # change whole line
o   # make a new line after current line
O   # make a new line before current line
r   # replace one character
R   # replace many characters

Copy, cut and paste

y   # copy selected text
yy  # copy current line
:y  # copy current line
d   # cut selection
dd  # cut current line
p   # paste after cursor or after line
P   # paste before cursor or before line

Deleting

x   # Delete character to the right of cursor
X   # delete character to the left of cursor
D   # delete line contents
dd  # delete current line
:d  # delete current line

Searching

:/search_string  # search forward for string
:?search_string  # search back for string
n   # jump to next search result
N   # jump to previous search result

Replacing

:s/pattern/string/flags   # (flag g - replace all, flag c - confirm replaces)
&   # repeat last replace command

Exiting

:x  # exit saving changes
ZZ  # exit saving changes
:q  # exit if no changes were made
:q! # exit ignoring changes

Misc

~   # CAPS on on / off
J   # join lines
.   # execute last text changing command
u   # unco last command
U   # undo all changes to line

Files

:w file    # write file
:r file    # read file after line
:n         # go to next line
:p         # go to previous line
:e file    # edit file
!!program  # replace line with the output of program

Buffers

"adw # cut word to buffer a
"qdw # cut word info buffer q
"fdd # cut current line into buffer f
"ap  # paste from buffer a
"qp  # paste from buffer q
"fp  # paste from buffer f

Markers

mt  # set marker t for this line
mg  # set marker g for this line
`t  # go to the begining of marker t line
`g  # go to the begining of marker g line
't  # go to first non blank character of marker t line
'g  # go to first non blank character of marker g line

Ranges

:n,m # lines from n to m
:.  # range - current line
:$  # range - last line
:'c # range - marker c
:%  # range - all lines in file
:g/pattern/  # range - all lines that contain pattern