Mounting a remote machine’s directory on your local machine using sshfs

Recently I purchased a hosting plan from a hosting provider, had to pay them a lot of money. The give alot of free disk space on their server. I can acess the remote server using nPanel but I have to login to the hosting provider first and then open a couple of links to get the nPanel and I can use the file manager provided by the hosting service to upload files. But that’s very inconvenient.

The other way to access the server folders is to use ssh and manipulate my data on the server. I can also use rsync on my local linux machine to push the data on the remote server or vice-versa.

There is another way using sshfs using this we can mount a remote directory on our local machine like this. For example I can mount my raspberry pi on a local folder like this

sshfs pi@192.168.18.10: pi_remote/
umount pi_remote/  // to unmount the directory
Code language: JavaScript (javascript)

Write a Hello World C++ program in linux

Writing a hello world C++ program in linux is easy. Here are the step

  1. Create a file with cpp extension. Let’s call it program.cpp
  2. write some code in the file we created in previous step
  3. compile, build and link
  4. Run the program
#include <iostream>
using namespace std;
int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
  return 0;
}
Code language: PHP (php)

Installing Pi-hole on Raspberry pi

Even though we can install pi-hole directly on raspberry pi. In this post I will show how to run it in docker container. So we have to have docker installed on raspberry pi. First of all please read the previous post where we installed docker on raspberry pi. To run pi-hole we will create a docker container using pi-hole image.

  1. Create a directory in your raspberry pi, like below
mkdir docker-test
cd docker-test
touch docker-compose.yml
nano docker-compose.ymlCode language: CSS (css)

Now paste the code in the docker-compose.yml

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
      - "80:80/tcp"
    environment:
      TZ: 'America/Chicago'
      # WEBPASSWORD: 'set a secure password here or it will be random'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
    restart: unless-stoppedCode language: PHP (php)

After this save the docker-compose.yml file. Pressing Ctrl+o in nano and Ctrl+x to exit nano. Then run the following command to run the pi-hole container, make sure while running the command that you are in same directory where yml file is located, otherwise an error will be shown “no configuration file present” or similar.

sudo docker compose up -d

This will download the pi-hole image (if not already donwloaded), create a container based on it and run it. However you can have a conflict of ports and this might not run. For example I had a apache server running on port 80 therefore there was a conflict. So you can change the port section in the yml file as below

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    ports:
      - "53:53/tcp"
      - "53:53/udp"
    #  - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
      - "8080:80/tcp"
    environment:
      TZ: 'America/Chicago'
      # WEBPASSWORD: 'set a secure password here or it will be random'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
    restart: unless-stopped
Code language: PHP (php)

I have changed port 80 to 8080 so that docker listens on port 8080 but internally the pi-hole will be made to be believe that it is listening on port 80. Furthermore I have commented port 67 because I do not want pi-hole to be used as dhcp server.

To stop the pi-hole container, you can type the command

sudo docker stop pihole

pihole is the also name of the container, that we created earlier.

To list name of the containers you can type

sudo docker ps -a

This will show all containers , running or stopped.

Pihole URL acesss and username, password

Once the container is running we can use following url to access the pihole. If you had changed port to 8080 then use the port accordingly in the url, otherwise you can avoid mentioning port in the url. For example if your raspberry pi ip address is 192.168.18.10 then the Url looks like below

http://192.168.18.10:8080/admin

http://192.168.18.10/admin

If pihole asks password in the login page

if the pihole asks the password in the login url page or admin page, you can reset it as follows by giving the command to pihole. Since pihole is running in the container and not accessible outside the container, therefore we will issue the command to pihole thourgh docker as follows. Make sure container is running before this command, otherwise it makes no sense.

docker exec -ti <name_of_your_container> pihole -a -pCode language: HTML, XML (xml)

Since out container name is also pihole we run it like this. Note, we have to use sudo before the command

docker exec -ti pihole pihole -a -p

This will reset the password, you can give a new password and login to the url again.

Adding DNS to the router

After having setup pihole, we need to point the DNS server of router to the pihole which is your raspberry pi ipaddress. In otherwords, now your raspberry pi is acting as a DNS server. Depending on your router you have first login to the router configuration page. open your browser and input the login url. You can check the router admin page url, username and password on your router’s back. Once you login , you can find appropriate menu to enter the DNS address. You you use your Raspberry pi ip address in that field and save it. You may have to restart the router. To verify if your DNS server is hitting, you have to login to pihole administration page whose URL was given above and it will show you the details of clients. It is suggested that you also enter same value in the secondary DNS server field.

Caveats using Pi-hole

Android google chrome browser problem

I had problem with android 11 doing browsing so I fixed it as follows. If on android phone chrome browser is often showing DNS error and not browsing an allowed website. You should open the app list in android and clear the cache and storage of chrome. Furthermore you can use firefox as default browser of android.

Some devices by pass Pi-hole (due to Ipv6 or custom dns)

Some useful commands are below

sudo resolvectl flush-caches // to flush local dns caches
sudo resolvectl statistics   // to check stats of dns cache
dnslookup domain-name        // to check ip address returned from default dns server
dnslookup domain-name ip-address-of-dns //to explicitly check results returned by the given dns serverCode language: JavaScript (javascript)

I had added some custom domains representing my own devices on the local network, so that I do not have to type LAN ips, for example mypi.com, myzbook.com etc. However I noticed that some machines were occasionally hitting the pihole DNS and sometimes not, and therefore getting real ip address of the above domains. You can try following resolutions.

Firstly, on your machine where your domain is not hitting the pihole, make sure you have no custom DNS servers and DHCP is automatic in your network connection. This way the router assigns the DNS server it has in its configuration to the connection.

I had this custom DNS in my connection which I had to change to automatic

Secondly you may have to disable IPV6 publishing or announcement by your router. In my case I had to disable both enable DHCPv6 Server and Enable Router Advertisement. Before disabling them my network/wifi connection in Ubuntu 22.01 was displaying this

Both of these were enabled by default and I had to uncheck/disable both of the settings below to let DNS 6 disappear from my network connection. You can manually do it as well on each such device but if your router is not publishing IPV6 DHCP server and route advertisement then it works for all devices in general.

    After updating the router settings, refresh your network connected or better yet restart router.

    DNS resolution not available

    If you have problem updating gravity ( a pi-hole database which is updated regularly to block new domains) and you get an error like “Dns resolution not available then you can add a dns: -127.0.0.1 entry in the docker-compose.yml file and reissue the command to recompile, run as given above. After update the docker-compose.yml will look like this

    # More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
    services:
      pihole:
        container_name: pihole
        image: pihole/pihole:latest
        # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
        ports:
          - "53:53/tcp"
          - "53:53/udp"
        #  - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
          - "8080:80/tcp"
        environment:
          TZ: 'America/Chicago'
          # WEBPASSWORD: 'set a secure password here or it will be random'
        # Volumes store your data between container upgrades
        
        dns:
           - 127.0.0.1
    
        volumes:
          - './etc-pihole:/etc/pihole'
          - './etc-dnsmasq.d:/etc/dnsmasq.d'
        #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
        cap_add:
          - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
        restart: unless-stopped
    Code language: PHP (php)

    References used

    Installing docker, docker-compose on Raspberry Pi

    Installed docker on raspberry pi 3b, OS version 11/bullseye. In the next post we will install pihole in docker.

    Followed the link https://docs.docker.com/engine/install/raspberry-pi-os/

    First we need to remove all unofficial packages, so type the following command. You may not have any packages installed, but let’s do it.

    for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; doneCode language: JavaScript (javascript)

    There are different methods to install docker, but we will use docker’s apt repository method .

    Install using apt repository

    Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository. Afterward, you can install and update Docker from the repository.

    1.Setup docker’s apt repository

      # Add Docker's official GPG key:
      sudo apt-get update
      sudo apt-get install ca-certificates curl
      sudo install -m 0755 -d /etc/apt/keyrings
      sudo curl -fsSL https://download.docker.com/linux/raspbian/gpg -o /etc/apt/keyrings/docker.asc
      sudo chmod a+r /etc/apt/keyrings/docker.asc
      
      # Add the repository to Apt sources:
      echo \
        "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/raspbian \
        $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
        sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
      sudo apt-get updateCode language: PHP (php)

      2. Install latest packages

      sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginCode language: JavaScript (javascript)

      3. Verify that the installation is successful by running the hello-world image:

      sudo docker run hello-world

      Uninstall docker, docker-compose

      1. Uninstall docker engine, cli, containerd and docker compose packages
      sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extrasCode language: JavaScript (javascript)

      2.Remove directories where images, volumes and containers are stored

      sudo rm -rf /var/lib/docker
      sudo rm -rf /var/lib/containerdCode language: JavaScript (javascript)

      3.Finally remove source keys and keyrings

      sudo rm /etc/apt/sources.list.d/docker.list
      sudo rm /etc/apt/keyrings/docker.ascCode language: PHP (php)

      How to Install the PostGIS Extension for PostgreSQL

      Introduction

      PostGIS is a full-fledged Geographic Information System (GIS) data modeling tool. It has many GIS-specific data types and functions. PostGIS is available as an extension for the PostgreSQL database; it is not a standalone software. This guide shows how to install PostGIS on PostgreSQL when installed on a Vultr cloud server or a Vultr Managed Database.

      Prerequisites

      Before starting with this guide, you should have:

      By default, a standalone PostgreSQL installation connects to the postgres database as the user postgres. An instance of Vultr Managed Databases for PostgreSQL connects to the defaultdb database as the user vultradmin. Following this guide without explicitly connecting to a specific database will load PostGIS into the default database.

      Note that =# refers to the PostgreSQL psql prompt, # refers to the root prompt on the operating system, and $ refers to a regular user prompt.

      Compatibility

      The instructions in this guide are based on PostgreSQL version 14 and PostGIS 3.2 running on Ubuntu 22.04 and Vultr Managed Databases for PostgreSQL. They should be compatible with all recent versions of the software and operating systems. Note that in the case of standalone servers, you need to have only one version of PostgreSQL installed. Handling two or more versions installed on the same system is beyond the scope of this guide

      Step 1: Install Packages for PostGIS

      Assuming that PostgreSQL is already available, PostGIS installation consists of 2 steps:

      1. Install postgis, the PostGIS package, from the operating system’s package manager.
      2. Load PostGIS into a PostgreSQL database.

      While this guide demonstrates the first step for Ubuntu, the general procedure is the same for all operating systems. The second step is the same for both standalone servers as well as Vultr Managed Databases for PostgreSQL.

      Option 1 – Install on Ubuntu

      Optional – Check Compatibility

      In general, there should be no compatibility issues on Ubuntu. Check the version of PostgreSQL installed on your operating system. On the PostgreSQL command line, enter:

      =# SELECT version();
      Code language: PHP (php)

      Check the version of PostGIS available on the apt package manager:

      $ apt search ^postgis$
      

      Check the compatibility page to ensure the available version of PostGIS is compatible with the installed version of PostgreSQL.

      Install the Package

      Install the postgis package on Ubuntu using the apt package manager.

      # apt install postgis
      Code language: PHP (php)

      This will install the latest version of PostGIS available for the operating system.

      Option 2 – Install on Vultr Managed Databases for PostgreSQL

      On Vultr Managed Databases for PostgreSQL, the PostGIS extension package is already installed. You only need to load it (as shown in the next step).

      Step 2: Load the PostGIS Extension

      The second step of the installation is the same across both standalone servers and managed databases. Log in to the PostgreSQL command line using the psql tool, pgAdmin, or another front-end tool that allows you to issue queries to the PostgreSQL server. For Vultr Managed Databases for PostgreSQL, find the credentials from the Connection Details page of your instance.

      Check Availability

      Check if the extension is available to be loaded:

      =# SELECT * FROM pg_available_extensions;
      Code language: PHP (php)

      After installing PostGIS on the operating system, it should be included in this list.

      Load the Extension

      Use the CREATE EXTENSION command of PostgreSQL to create a new extension for PostGIS:

      =# CREATE EXTENSION postgis ;
      Code language: PHP (php)

      The PostGIS extension should now be loaded into the database.

      Check Installation

      Check that the PostGIS extensions are loaded:

      =# SELECT * FROM pg_extension ;
      Code language: PHP (php)

      The above command shows the list of all loaded extensions. You can also check the version of PostGIS installed:

      =# SELECT postgis_version();
      Code language: PHP (php)

      Conclusion

      PostGIS has now been loaded into your PostgreSQL database. The PostGIS documentation is a good starting point to learn more about how to handle GIS data in PostgreSQL.

      Xcode is not running the application

      sometimes xcode if configured to build a framework as well as an app. If it builds your project fine but does not run it then try this

      To fix it I had to go to the menu Product > Edit Scheme… > Select “Run ” (in the sidebar) > Info (tab). In here is a drop down box labeled Executable, select it and choose your app that you wish to launch when the Run button is clicked.

      Git cheat sheet

      Install

      GitHub Desktop

      desktop.github.com

      Git for All Platforms

      git-scm.com

      Configure tooling

      Configure user information for all local repositories

      $ git config --global user.name "[name]"

      Sets the name you want attached to your commit transactions

      $ git config --global user.email "[email address]"

      Sets the email you want attached to your commit transactions

      $ git config --global color.ui auto

      Enables helpful colorization of command line output

      Branches

      Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to. Use git status to see which branch that is.

      $ git branch [branch-name]

      Creates a new branch

      $ git checkout [branch-name]

      Switches to the specified branch and updates the working directory

      $ git merge [branch]

      Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.

      $ git branch -d [branch-name]

      Deletes the specified branch

      Create repositories

      When starting out with a new repository, you only need to do it once; either locally, then push to GitHub, or by cloning an existing repository.

      $ git init

      After using the git init command, link the local repository to an empty GitHub repository using the following command:

      $ git remote add origin [url]

      Turn an existing directory into a Git repository

      $ git clone [url]

      Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits

      The .gitignore file

      Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore. You can find helpful templates for .gitignore files at github.com/github/gitignore.

      Synchronize changes

      Synchronize your local repository with the remote repository on GitHub.com

      $ git fetch

      Downloads all history from the remote tracking branches

      $ git merge

      Combines remote tracking branches into current local branch

      $ git push

      Uploads all local branch commits to GitHub

      $ git pull

      Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge

      Make changes

      Browse and inspect the evolution of project files

      $ git log

      Lists version history for the current branch

      $ git log --follow [file]

      Lists version history for a file, including renames

      $ git diff [first-branch]...[second-branch]

      Shows content differences between two branches

      $ git show [commit]

      Outputs metadata and content changes of the specified commit

      $ git add [file]

      Snapshots the file in preparation for versioning

      $ git commit -m "[descriptive message]"

      Records file snapshots permanently in version history

      Redo commits

      Erase mistakes and craft replacement history

      $ git reset [commit]

      Undoes all commits after [commit], preserving changes locally

      $ git reset --hard [commit]

      Discards all history and changes back to the specified commit

      CAUTION! Changing history can have nasty side effects. If you need to change commits that exist on GitHub (the remote), proceed with caution. If you need help, reach out at github.community or contact support.

      Get your local Git repository on Bitbucket

      Step 1: Switch to your repository’s directory

      cd /path/to/your/repo

      Step 2: Connect your existing repository to Bitbucket

      git remote add origin https://ahmed@bitbucket.org/ahmed/flickerupload.gitgit push -u origin master

      Changing Android Studio editor font

      Its a bit tricky and I couldn’t figure it out immediately how to do that. To do that go to File->Settings->Editor-> Colors and Fonts->Font. You will notice the font size is greyed out. There you press the save as button on the default or Darcula Scheme. Then press OK, once you do that a copy of the existing profiles is made then you can edit font size.
      Hope it helps..