Wednesday, August 31, 2022

Fortigate VM Config

 A little helpful tip to get an interface configured and able to route.


  1. At the FortiManager VM login prompt, enter the username admin, then press Enter. By default, there is no password.

  2. Using CLI commands, configure the port1 IP address and netmask.

For example:

config system interface

edit port1

set ip <IP address> <netmask>

end



  1. To configure the default gateway, enter the following commands:

    config system route

    edit 1

    set device port1

    set gateway <gateway_ipv4_address>

    end

Friday, August 26, 2022

Find examples

 A few examples of using the "find" command to make your life easier.


My brother asked about searching through a folder to find images based on date range and then moving them to a new folder.  Sounds simple enough and I'm sure there are multiple ways to accomplish the same thing.  

As for me, I'll keep it simple and run the following little script.


#!/bin/bash
for i in $(find dir_to_search/ -newermt "2011-01-01" ! -newermt "2011-12-31"); do
mv $i /new_dir/
done


Another example of just doing the find for the date range:

find . -type f -newermt 2020-10-01 ! -newermt 2022-10-01






Tuesday, August 23, 2022

Fortigate -> Configure PiHole (like) DNS Setup

 FortiGate -> Pi Hole (like) Config 

I hate ads.

Fortigate has the ability to add external Block Lists and I determined to find lists and configure it to act much like PiHole.

Core Steps
  • Add external filter lists
  • Set up a DNS filter, block the external filter lists
  • Set up a DNS server on the Fortigate with the DNS filter enabled

External lists

 Add the external lists. This is an example of 8 lists that are a mix of advertisers and trackers.
  • SSH to Fortigate.
  • At the CLI you can paste the following:

config system external-resource
    edit "Disconnect-Ad-Filter"
        set type domain
        set category 194
        set resource "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt"
        set refresh-rate 60
    next
    edit "AdGuard"
        set type domain
        set category 192
        set resource "https://v.firebog.net/hosts/AdguardDNS.txt"
        set refresh-rate 60
    next
    edit "Firebog"
        set type domain
        set category 193
        set resource "https://v.firebog.net/hosts/Easylist.txt"
        set refresh-rate 60
    next
    edit "Firebog-Privacy"
        set type domain
        set category 195
        set resource "https://v.firebog.net/hosts/Easyprivacy.txt"
        set refresh-rate 60
    next
    edit "Fireblog-Admiral"
        set type domain
        set category 196
        set resource "https://v.firebog.net/hosts/Admiral.txt"
        set refresh-rate 60
    next
    edit "Fireblog-Privacy-2"
        set type domain
        set category 197
        set resource "https://v.firebog.net/hosts/Prigent-Ads.txt"
        set refresh-rate 60
    next
    edit "OISD"
        set type domain
        set category 198
        set resource "https://dbl.oisd.nl/"
        set refresh-rate 60
    next
    edit "OISD-IP"
        set type address
        set resource "https://hosts.oisd.nl/"
        set refresh-rate 60
    next
end
config system dns-server
end

DNS Filter

  • Add a DNS filter. 
    • You can do this under the 'Security Profiles' tab in the GUI of the Fortigate. 
      • Enable the option FortiGuard Category Based Filter

  • In the category filter list, locate an entry called 'Remote Categories'. Open, you will find seven of the external entries we added via CLI. 
    •     Set all of them to 'Redirect to Block Portal'.

  • At the bottom of the menu, you will find the option External IP Block lists
    • Click at the + sign and select the entry 'OSID-IP'.

Now, all eight lists are active in this DNS filter profile.


Set up a DNS Server

Setting up a DNS server is most easy done by CLI (like most of things). Paste this code to your CLI to setup the server. Change the dnsfilter-profile to the name of your DNS profile.

    edit "internal"
        set mode forward-only
        set dnsfilter-profile "Your-DNS-Filter"
    next


After setting up your DNS server
  • Publish it with your DHCP.

NOTE: This should get rid of many ads (YouTube ads cannot be blocked this way).

Samba - Test Config File

 You can easily test your Samba server for configuration errors. It check an smb.conf configuration file for internal correctness. If this program reports no problems, you can use the configuration file with confidence that smbd will successfully load the configuration file.

Open a shell prompt and then type the following command:# testparm
OR# testparm /etc/samba/smb.conf
We will see the following message on screen:
Load smb config files from /usr/local/etc/smb4.conf Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions

If you hit the [Enter], key you will see other details

OwnCloud Manual import of data

If you are here, you've obviously started to use Owncloud and found that importing the mountain of data you want accessible is painful. So what if you have gigabytes of files to add to your ownCloud server? You can of course use the desktop client to sync all those files, but what if we were talking about almost a terabyte?

Add files manually to your ownCloud server

This is probably the quickest and less complicated way of adding files. There are many alternative ways to transfer your files to your ownCloud server:

      • FTP Upload;
      • SCP Upload;
      • Local disk to ownCloud disk transfer;
      • USB disk to ownCloud disk transfer.

It's just as simple as dragging a folder to another folder. The only problem is that you might not know yet where ownCloud files are stored. I made life a little bit easier with this nifty little Bash snippet that automatically finds your ownCloud data directory:

find / -name config.php 2>/dev/null | while read line ; do cat "$line" | grep " 'datadirectory'" ; done

Your output should then look something like this:

ownCloud Data Directory Snippet

So according to the snippet of code my ownCloud data directory is located at /var/www/owncloud/data so let's cd into that directory to check out what's in there.

ownCloud Data Directory Contents

As you can see, we have multiple files in here. My ownCloud username is bart, so let's take a look in that folder.

ownCloud Data Directory Closer Look

Now this looks interesting. If I check my ownCloud web portal I can see that the directory structure is the same:

ownCloud Default Web Interface Folders

So I created a folder called TestFolder123 in the web interface and executed ls -la on the server's console.

ownCloud Default Web Interface With Test Folder

ownCloud Server Console Test Folder

So I tried to do the same thing, but vice versa. I created a folder on the console side, updated the folder's ownership and afterwards checked if the folder appeared in the web interface, with some surprising results:

ownCloud Server Console Test Folder 2

ownCloud Default Web Interface Without Console Test Folder

What the heck?!

Where did my folder go??!

Okay.. let me explain what's going on here. The ownCloud system basically expects two things from a file/folder in order to be indexed as a file:

      • The file/folder needs to be physically available;
      • The file/folder needs to exist in the ownCloud database.

Moving a file/folder into ownCloud's data directory doesn't add it to the database automatically. Luckily, the ownCloud developers were kind enough to create a command line tool called occ that can manually add missing files and folders to the ownCloud database. You can run the following snippet on your server to check where this utility is located on the local file system:

find / -name "occ" 2>/dev/null

Which outputs the following on my demo server:

OCC Binary Location

All you need to do is cd into that folder (in my case /var/www/owncloud) and run the following snippet:

sudo -u www-data php occ files:scan --all

Where www-data is the user your web server runs on.

    Another option would be a command that scans a specific folder or user.  In this example, the username is "bart" and the folder to scan is  in the "files" directory called "temp2" 

 

NOTE: the path is not the full path in the file system but must start with the username.  For example my installation & data directory is located in /var/www/owncloud/data   all the user data is located in a folders (named by username), followed by a "files" folder and then any folders/directories created there after for the given user.

If you try to use a fully qualified path afer --path directive,  you will encounter the error

Unknown user 1 var

sudo -u www-data php occ files:scan --path bart/files/temp2

Further more, if you wanted to scan all the files and directories for a given user, you could run the following, where "bart" is the ownCloud username.

sudo -u www-data php occ files:scan bart

 And now, it is time for the results:

OCC Output From The Console

Positive Results In The Web Interface

YEAH!! So this command has definitely helped. Now you can add all your files directly into your ownCloud data folder without having to sync from the desktop client.


Wednesday, August 3, 2022

JellyFin Media Server Install - Ubuntu 18.04

How to Install Jellyfin Media Server (Ubuntu 18.04)

Jellyfin is an open source fork of Emby Media Server that allows you to organize and stream your movies, shows, music, and photos. Update Your Server

Before installing Jellyfin, you’ll want to make sure your server’s package management repositories are fully up to date. Run this command to get the latest package listings and update installed packages to their latest versions:

sudo apt update && sudo apt upgrade

Download and Install Jellyfin

Jellyfin is nice and easy to install and keep up to date on Ubuntu as there is an official repository.  

First, install apt-transport-https.

sudo apt install apt-transport-https

Next, download the gpg key and install the repo.

wget -O - https://repo.jellyfin.org/ubuntu/jellyfin_team.gpg.key | sudo apt-key add -
sudo echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/ubuntu $( lsb_release -c -s ) main" | sudo tee /etc/apt/sources.list.d/jellyfin.list

Now update your package listing and install Jellyfin

sudo apt update
sudo apt install jellyfin

Create Library Path

We’ll create a movies directory in /jellyfin-library. You can also create a shows, music, or photos directory at this time. The library directories can be created anywhere the jellyfin user has read access to. I typically serve content like this from /var/www

sudo mkdir -p /var/www/jellyfin/jellyfin-library/movies
sudo mkdir -p /var/www/jellyfin/jellyfin-library/photos

Jellyfin Setup

To start setting up Jellyfin, navigate to http://localhost:8096 in your web browser or http://ip_of_your_jellyfin_server:8096  if you are accessing it from a different computer on your local network.

Select your language and click Next.

Create a username and password. Click Next. ( you don't need a "jellyfin" username, you can use a name of your choosing.)

We’ll add a library later on. For now, just click Next.

Confirm your language and country. Click Next.

Make sure the Allow remote connections to this Jellyfin Server option is enabled. Click Next.

Click Finish.

Add a Library

After setup is complete, Jellyfin should ask you to sign in. Go ahead and enter your credentials and sign in.

Click on the icon in the top right corner of the portal to get to settings.

Click Libraries.

Click Add Media Library.

Select your content type and give it a name. Click Folders.

Select the library directory you created earlier and click ok.  

Click ok.

Add Media to Your Library

The easiest way to upload your media is with SFTP.

These two Emby wiki articles will show you how to properly organize your media so Jellyfin can understand it and fetch the proper metadata.

Movies: https://github.com/MediaBrowser/Wiki/wiki/Movie-naming

TV Shows: https://github.com/MediaBrowser/Wiki/wiki/TV-naming

Once you’ve added your media, you’ll need to scan your library files before Jellyfin will see them. Do this by clicking on the three dots next to your library and clicking Scan Library.

SSL

Jellyfin does not come with SSL built in. If you want more privacy and to protect your login credentials from potential compromise, it’s a good idea to add SSL. Once you have obtained a certificate and uploaded it to your server, click on the icon at the top right of your Jellyfin portal.

Click Networking.

Add the certificate path under Custom ssl certificate path.

Enjoy Your Media!

Congratulations! Everything should be working at this point. Now you can enjoy your media with one of Jellyfin’s client apps or in your web browser by navigating to http://ip_of_jellyfin_server:8096

Monday, August 1, 2022

Basic Linux Commands

 

Linux Basic Commands

1. pwd command

Use the pwd command to find out the path of the current working directory (folder) you’re in. The command will return an absolute (full) path, which is basically a path of all the directories that starts with a forward slash (/). An example of an absolute path is /home/username.

2. cd command

To navigate through the Linux files and directories, use the cd command. It requires either the full path or the name of the directory, depending on the current working directory that you’re in.

Let’s say you’re in /home/username/Documents and you want to go to Photos, a subdirectory of Documents. To do so, simply type the following command: cd Photos.

Another scenario is if you want to switch to a completely new directory, for example,/home/username/Movies. In this case, you have to type cd followed by the directory’s absolute path: cd /home/username/Movies.

There are some shortcuts to help you navigate quickly:

  • cd .. (with two dots) to move one directory up
  • cd to go straight to the home folder
  • cd- (with a hyphen) to move to your previous directory

On a side note, Linux’s shell is case sensitive. So, you have to type the name’s directory exactly as it is.

3. ls command

The ls command is used to view the contents of a directory. By default, this command will display the contents of your current working directory.

If you want to see the content of other directories, type ls and then the directory’s path. For example, enter ls /home/username/Documents to view the content of Documents.

There are variations you can use with the ls command:

  • ls -R will list all the files in the sub-directories as well
  • ls -a will show the hidden files
  • ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.

4. cat command

cat (short for concatenate) is one of the most frequently used commands in Linux. It is used to list the contents of a file on the standard output (sdout). To run this command, type cat followed by the file’s name and its extension. For instance: cat file.txt.

Here are other ways to use the cat command:

  • cat > filename creates a new file
  • cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output of them in a new file (3)
  • to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt

5. cp command

Use the cp command to copy files from the current directory to a different directory. For instance, the command cp scenery.jpg /home/username/Pictures would create a copy of scenery.jpg (from your current directory) into the Pictures directory.

6. mv command

The primary use of the mv command is to move files, although it can also be used to rename files.

The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and the destination’s directory. For example: mv file.txt /home/username/Documents.

To rename files, the Linux command is mv oldname.ext newname.ext

7. mkdir command

Use mkdir command to make a new directory — if you type mkdir Music it will create a directory called Music.

There are extra mkdir commands as well:

  • To generate a new directory inside another directory, use this Linux basic command mkdir Music/Newfile
  • use the (parents) option to create a directory in between two existing directories. For example, mkdir -p Music/2020/Newfile will create the new “2020” file.

8. rmdir command

If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.

9. rm command

The rm command is used to delete directories and the contents within them. If you only want to delete the directory — as an alternative to rmdir — use rm -r.

Note: Be very careful with this command and double-check which directory you are in. This will delete everything and there is no undo.

10. touch command

The touch command allows you to create a blank new file through the Linux command line. As an example, enter touch /home/username/Documents/Web.html to create an HTML file entitled Web under the Documents directory.

11. locate command

You can use this command to locate a file, just like the search command in Windows. What’s more, using the -i argument along with this command will make it case-insensitive, so you can search for a file even if you don’t remember its exact name.

To search for a file that contains two or more words, use an asterisk (*). For example, locate -i school*note command will search for any file that contains the word “school” and “note”, whether it is uppercase or lowercase.

12. find command

Similar to the locate command, using find also searches for files and directories. The difference is, you use the find command to locate files within a given directory.

As an example, find /home/ -name notes.txt command will search for a file called notes.txt within the home directory and its subdirectories.

Other variations when using the find are:

  • To find files in the current directory use, find . -name notes.txt
  • To look for directories use, / -type d -name notes. txt

13. grep command

Another basic Linux command that is undoubtedly helpful for everyday use is grep. It lets you search through all the text in a given file.

To illustrate, grep blue notepad.txt will search for the word blue in the notepad file. Lines that contain the searched word will be displayed fully.

14. sudo command

Short for “SuperUser Do”, this command enables you to perform tasks that require administrative or root permissions. However, it is not advisable to use this command for daily use because it might be easy for an error to occur if you did something wrong.

15. df command

Use df command to get a report on the system’s disk space usage, shown in percentage and KBs. If you want to see the report in megabytes, type df -m.

16. du command

If you want to check how much space a file or a directory takes, the du (Disk Usage) command is the answer. However, the disk usage summary will show disk block numbers instead of the usual size format. If you want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line.

17. head command

The head command is used to view the first lines of any text file. By default, it will show the first ten lines, but you can change this number to your liking. For example, if you only want to show the first five lines, type head -n 5 filename.ext.

18. tail command

This one has a similar function to the head command, but instead of showing the first lines, the tail command will display the last ten lines of a text file. For example, tail -n filename.ext.

19. diff command

Short for difference, the diff command compares the contents of two files line by line. After analyzing the files, it will output the lines that do not match. Programmers often use this command when they need to make program alterations instead of rewriting the entire source code.

The simplest form of this command is diff file1.ext file2.ext

20. tar command

The tar command is the most used command to archive multiple files into a tarball — a common Linux file format that is similar to zip format, with compression being optional.

This command is quite complex with a long list of functions such as adding new files into an existing archive, listing the content of an archive, extracting the content from an archive, and many more. Check out some practical examples to know more about other functions.

21. chmod command

chmod is another Linux command, used to change the read, write, and execute permissions of files and directories. As this command is rather complicated, you can read the full tutorial in order to execute it properly.

22. chown command

In Linux, all files are owned by a specific user. The chown command enables you to change or transfer the ownership of a file to the specified username. For instance, chown linuxuser2 file.ext will make linuxuser2 as the owner of the file.ext.

23. jobs command

jobs command will display all current jobs along with their statuses. A job is basically a process that is started by the shell.

24. kill command

If you have an unresponsive program, you can terminate it manually by using the kill command. It will send a certain signal to the misbehaving app and instructs the app to terminate itself.

There is a total of sixty-four signals that you can use, but people usually only use two signals:

  • SIGTERM (15) — requests a program to stop running and gives it some time to save all of its progress. If you don’t specify the signal when entering the kill command, this signal will be used.
  • SIGKILL (9) — forces programs to stop immediately. Unsaved progress will be lost.

Besides knowing the signals, you also need to know the process identification number (PID) of the program you want to kill. If you don’t know the PID, simply run the command ps ux.

After knowing what signal you want to use and the PID of the program, enter the following syntax:

kill [signal option] PID.

25. ping command

Use the ping command to check your connectivity status to a server. For example, by simply entering ping google.com, the command will check whether you’re able to connect to Google and also measure the response time.

26. wget command

The Linux command line is super useful — you can even download files from the internet with the help of the wget command. To do so, simply type wget followed by the download link.

27. uname command

The uname command, short for Unix Name, will print detailed information about your Linux system like the machine name, operating system, kernel, and so on.

28. top command

As a terminal equivalent to Task Manager in Windows, the top command will display a list of running processes and how much CPU each process uses. It’s very useful to monitor system resource usage, especially knowing which process needs to be terminated because it consumes too many resources.

29. history command

When you’ve been using Linux for a certain period of time, you’ll quickly notice that you can run hundreds of commands every day. As such, running history command is particularly useful if you want to review the commands you’ve entered before.

30. man command

Confused about the function of certain Linux commands? Don’t worry, you can easily learn how to use them right from Linux’s shell by using the man command. For instance, entering man tail will show the manual instruction of the tail command.

31. echo command

This command is used to move some data into a file. For example, if you want to add the text, “Hello, my name is John” into a file called name.txt, you would type echo Hello, my name is John >> name.txt

32. zip, unzip command

Use the zip command to compress your files into a zip archive, and use the unzip command to extract the zipped files from a zip archive.

33. hostname command

If you want to know the name of your host/network simply type hostname. Adding a -i to the end will display the IP address of your network.

34. useradd, userdel command

Since Linux is a multi-user system, this means more than one person can interact with the same system at the same time. useradd is used to create a new user, while passwd is adding a password to that user’s account. To add a new person named John type, useradd John and then to add his password type, passwd 123456789.

To remove a user is very similar to adding a new user. To delete the users account type, userdel UserName

35. watch command

Sometimes you want to "watch" a process in a different way than say the "top" command.  For example, if I had a rsync running and wanted to watch the disk free or disk usage, I could run the following commands.  The -h shows the output in "human readable" format and the -m shows it in megabytes (I believe you can use -g or -t as well for gigabyte or terabyte).

watch df -hm

watch du -hm

36. rsync command

Rsync (Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems.

With the help of the rsync command, you can copy and synchronize your data remotely and locally across directories, disks, and networks, perform data backups, and mirror between two Linux machines.

# rsync options source destination
Some common options used with rsync commands

  • -v : verbose
  • -r : copies data recursively (but don’t preserve timestamps and permission while transferring data.
  • -a : archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.
  • -z : compress file data.
  • -h : human-readable, output numbers in a human-readable format.

Bonus Tips and Tricks

Use the clear command to clean out the terminal if it is getting cluttered with too many past commands.

Try the TAB button to autofill what you are typing. For example, if you need to type Documents, begin to type a command (let’s go with cd Docu, then hit the TAB key) and the terminal will fill in the rest, showing you cd Documents.

Ctrl+C and Ctrl+Z are used to stop any command that is currently working. Ctrl+C will stop and terminate the command, while Ctrl+Z will simply pause the command.

If you accidentally freeze your terminal by using Ctrl+S, simply undo this with the unfreeze Ctrl+Q.

Ctrl+A moves you to the beginning of the line while Ctrl+E moves you to the end.

You can run multiple commands in one single command by using the “;” to separate them. For example Command1; Command2; Command3. Or use && if you only want the next command to run when the first one is successful.