Skip to content

Migrate from ViM to neovim

Migrate from ViM to neovim published on

Links used:

Main Steps

To use your existing .vimrc you can do this:

cat << EOF > ~/.config/nvim/init.vim
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
EOF

But if you want different init.vim than .vimrc (probably a good idea in the start phase) copy your stuff to:

cp -r ~/.vim/bundle ~/.config/nvim/bundle/
cp ~/.vimrc ~/.config/nvim/init.vim

You then could add a file ~/.config/nvim/ginit.vim for nvim-qt the Gvim equivalent of nvim. The normal distinction with has(gui_running) does not work properly. We can add all GUI Neovim specific stuff there, for my side it is something like:

colorscheme peachpuff
"map ctrl-tab to switch splits in terminal mode
nmap <silent> <C-Tab> :wincmd w<CR>

"open full screen
call rpcnotify(0, 'Gui', 'WindowMaximized', 1)

" Set Gui Font (`set guifont=` does not work in nvim-qt)
if has('nvim')
    GuiFont FreeMono:10
else

But later stuff in my .vimrc, like opening NERDTree, did not work in ginit.vim. For that I have extended my diff in init.vim:

if (has('gui_running') || get(g:, 'GuiLoaded', 1))

There is further a bug in nvim-qt in the newer package than the one from bionic, to open an additional empty buffer, see " https://github.com/equalsraf/neovim-qt/issues/423

This can be fixed with three lines at the end of init.vim:

if @% == ""
  bd
endif

Now you can use it with your ViM configuration. There is one difference, my beloved command gvim -d does not work directly, we have to use nvim-qt -- -d file1 file2. With Termina nvim, everything is ok.

Vundle Troubleshoot

To update Plugins, you probably have to change your Vundle configuration:

set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin("~/.config/nvim/bundle")

now you can run :PluginInstall and :PluginUpdate

Make Neovim Default

Add alternatives, for gvim somehow already /usr/bin/gvim.nvim-qt exist.

sudo update-alternatives --install $(which vim) vim $(which nvim) 10

and then config your choice:

sudo update-alternatives --config vim
sudo update-alternatives --config gvim

OpenVPN for Your PiHole

OpenVPN for Your PiHole published on

Goal

PiHole only available via OpenVPN

Steps to Achieve

Install OpenVPN on PiHole server according to https://ubuntu.com/server/docs/service-openvpn

At https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-16-04 you find a hint, how to set up a client config script.

create a file /etc/openvpn/client/make_config.sh on the server, below the adjusted to the current ubuntu configuration with easy-rsa

#!/bin/bash

# First argument: Client identifier

OPENVPNDIR=/etc/openvpn

KEY_DIR=$OPENVPNDIR/easy-rsa/pki
OUTPUT_DIR=$OPENVPNDIR/client/files
BASE_CONFIG=$OPENVPNDIR/client/base.conf

cat ${BASE_CONFIG} \
    <(echo -e '<ca>') \
    ${KEY_DIR}/ca.crt \
    <(echo -e '</ca>\n<cert>') \
    ${KEY_DIR}/issued/${1}.crt \
    <(echo -e '</cert>\n<key>') \
    ${KEY_DIR}/private/${1}.key \
    <(echo -e '</key>\n<tls-auth>') \
    ${OPENVPNDIR}/ta.key \
    <(echo -e '</tls-auth>') \
    > ${OUTPUT_DIR}/${1}.ovpn

Then you can run /etc/openvpn/client/make_config.sh CLIENTNAME and you get a ovpn file in /etc/openvpn/client/files/

You now can import that in your NetworkManager. The good old resolv.conf does not work, so you can add the IP address 10.8.0.1 of the VPN server as DNS in theconfiguration, where the pihole is running.

Add iptable rules

We have to block the external interface in the chain DOCKER-USER, see https://docs.docker.com/network/iptables/.

With these commands you can successful block everything, except port 80 from outside (for letsencrypt) and everything in the network 10.8.0.1/24 (openVPN)

sudo iptables -I DOCKER-USER -i ens3 ! -s 10.8.0.1/24 -j DROP
sudo iptables -I DOCKER-USER -i ens3 -m comment --comment "Accept all connections from VPN to Docker - Drop all other" ! -s 10.8.0.1/24 -j DROP
sudo iptables -I DOCKER-USER -i ens3 -p tcp --dport 80 -m comment --comment "Accept HTTP for letsencrypt" -j ACCEPT

# block all IPv6 traffic except 80 for letsencrypt and 22 for ssh
sudo ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo ip6tables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo ip6tables -A INPUT -j DROP

Save them (iptables-persistent must be installed):

iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6

Disable DNS Configuration from NetworkManager in Linux Mint

Disable DNS Configuration from NetworkManager in Linux Mint published on

Overview

The initial goal was, that my openvpn client configuration is able to set the DNS server.

Somehow that was not possible, even though we have set dhcp-option DNS 10.8.0.1 in the ovpn file.

But nevertheless, perhaps you want to get rid of your Network manager fingering in your resolv.conf convfig, then follow below:

Steps to Do

From https://askubuntu.com/a/623956/733411

  1. Edit /etc/NetworkManager/NetworkManager.conf
  2. Change to
    dns=none

Now feel free use your /etc/resolv.conf

e.g. like that:

nameserver 9.9.9.9          # quad 9
nameserver 149.112.112.112  # secondary quad 9
nameserver 2620:fe::fe      # IPv6 quad 9

Add Additional List to PiHole

Add Additional List to PiHole published on
  1. Go to your PiHole Admin at pihole.example.com/admin
  2. Go to Group Management >> Addlist
  3. Add the list you want there (e.g. https://dbl.oisd.nl)
  4. Click on the link "online" above, or go to Tools >> Update Gravity, or pihole.example.com/admin/gravity.php
  5. Update the database

Now you can check on the start page, there should be about 1Mio blocked domains.
I added https://dbl.oisd.nl, see https://oisd.nl/how2use

Update PiHole in docker-compose

Update PiHole in docker-compose published on

After you installed PiHole according to Install PiHole in docker-compose on Ubuntu Server you probably want to run regular updates.

With docker compose you simply could run this:

cd /opt/pihole/
sudo docker-compose stop
sudo docker-compose rm -f
sudo docker-compose pull
sudo docker-compose up -d

thanks to https://stackoverflow.com/a/39127792/7311363

Run Gmail in Different Firefox Profile on Linux Mint

Run Gmail in Different Firefox Profile on Linux Mint published on

I want to have a separate Firefox profile for my Google-Account, primary used by Gmail.
I use Linux Mint 19.3 Tricia.
I want to have an own icon in the task list, and the Gmail profile should not be opened in the Firefox "Icon Group" (don't know the correct name)

Steps to Achieve That

  1. Create a new Profile
    1. run Alt+F2
    2. enter firefox -P
    3. Add new profile, call it "Google"
  2. create a new file ~/.local/share/applications/GmailFF.desktop and with this content:
    [Desktop Entry]
    Name=Gmail Firefox
    Exec=firefox -P Google --no-remote --class GoogleFF
    Comment=Open Firefox with Google Profile
    Terminal=false
    Icon=checkgmail
    Type=Application
    StartupNotify=True
    StartupWMClass=GoogleFF

    The magic is coming from StartupWMClass, now Firefox for profile Google opens like a different program (found at https://www.techrepublic.com/article/how-to-run-two-different-firefox-profiles-at-once-on-linux/)

  3. Search for "Gmail Firefox" (or whatever Name you defined above) and open the profile.
    1. Pin the program to the tasklist
    2. Log in to Gmail-Account
    3. Change "Homepage and new windows" to gmail.com in Preferences
    4. Change "Default Search Engine" to Duckduckgo in Preferences
    5. Install add-ons Ublock Origin and Privacy Badger

Install PiHole in docker-compose on Ubuntu Server

Install PiHole in docker-compose on Ubuntu Server published on

Overview

This will document how to install PiHole on an Ubuntu server. PiHole will run in docker-compose with couple including some volumes from the host, so data could be stored during updates. The docker container for pihole should be is ephemeral.

Base Installation

the following steps are done according to pi-hole/docker-pi-hole

Run this steps:

  • Install docker compose installed on yourserver.example.com with sudo apt install docker-compose

  • For the following use install folder /opt/pihole

  • create docker-compose.yaml in /opt/pihole/, below is the final version incl the volumes which are added later:

    * version: "3"
    # More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
    services:
    pihole:
      container_name: pihole
      hostname: yourserver-pihole
      image: pihole/pihole:latest
      ports:
        - "53:53/tcp"
        - "53:53/udp"
        - "67:67/udp"
        - "80:80/tcp"
        - "443:443/tcp"
      environment:
        ADMIN_EMAIL: 'pihole@example.com'
        DNS1: '9.9.9.9'
        DNS2: '1.1.1.1'
        PIHOLE_BASE: '/opt/pihole'
        TZ: 'Europe/Zurich'
        WEBPASSWORD: '...'
      # Volumes store your data between container upgrades
      volumes:
        - './etc-pihole/:/etc/pihole/'
        - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
        - './letsencrypt:/opt/letsencrypt/'
        - './letsencrypt/lighttpd-external.conf:/etc/lighttpd/external.conf'
        - './fakewebroot/.well-known:/var/www/html/.well-known'
      # Recommended but not required (DHCP needs NET_ADMIN)
      #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
      cap_add:
        - NET_ADMIN
      restart: unless-stopped
  • You now can start it with with: docker-compose up --detach

  • You now can connect to http://yourserver.example.com/admin, make sure you don't login with the defined WEBPASSWORD, your conneciton isn't encrypted yet.

Certificate with Let's Encrypt

The Admin interface isn't encrypted yet, therefore we want to run the let's encrypt (certbot) on the host machine.

Below was done with information from https://discourse.pi-hole.net/t/enabling-https-for-your-pi-hole-web-interface/5771

  • We first create a folder /opt/pihole/fakewebroot and /opt/pihole/letsencrypt.
  • Above we already added two volumes:
    • ./letsencrypt:/opt/letsencrypt/ to copy the combined.pem and fullchain.pem in
    • ./fakewebroot/.well-known:/var/www/html/.well-known which will be used by certbot for to safe the challenge
  • With this we can run the following command to get the initial certificate:
    sudo certbot certonly --webroot /opt/pihole/fakewebroot/ -d yourserver.example.com
  • Lighttpd needs a combined.pem which is not automatically created by certbot, so merge them to the letsencrypt folder in our pihole directory. Further copy the fullchain:
    sudo cat /etc/letsencrypt/live/yourserver.example.com/privkey.pem  /etc/letsencrypt/live/yourserver.example.com/cert.pem > /opt/pihole/letsencrypt/combined.pem
  • create a lighttpd-external.conf file in the letsencrypt folder, the file was already added via volumes in the beginnen, but here again:
    • Add file with volume command
      ./letsencrypt/lighttpd-external.conf:/etc/lighttpd/external.conf
  • Add the following to the lighthttpd-external.conf, make sure you have the correct file names for ssl.pemfile and ssl.ca-file:

    $HTTP["host"] == "yourserver.example.com" {
      # Ensure the Pi-hole Block Page knows that this is not a blocked domain
      setenv.add-environment = ("fqdn" => "true")
    
      # Enable the SSL engine with a LE cert, only for this specific host
      $SERVER["socket"] == ":443" {
        ssl.engine = "enable"
        ssl.pemfile = "/opt/letsencrypt/combined.pem"
        ssl.ca-file =  "/opt/letsencrypt/fullchain.pem"
        ssl.honor-cipher-order = "enable"
        ssl.cipher-list = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"
        ssl.use-sslv2 = "disable"
        ssl.use-sslv3 = "disable"
      }
    
      # Redirect HTTP to HTTPS
      $HTTP["scheme"] == "http" {
        $HTTP["host"] =~ ".*" {
        url.redirect = (".*" => "https://%0$0")
        }
      }
    }

Renew Certificate Automatically

In the section before we already added the well-known folder /opt/pihole/fakewebroot/ and it is already added as volume in docker-compose.yaml

We now need a post action for the timer renewing, create a post hook file. Add the file with

sudo vim /etc/letsencrypt/renewal-hooks/post/redeploy-docker.sh

With this content:

cat /etc/letsencrypt/live/yourserver.example.com/privkey.pem /etc/letsencrypt/live/yourserver.example.com/cert.pem > /opt/pihole/letsencrypt/combined.pem
cat /etc/letsencrypt/live/yourserver.example.com/fullchain.pem /etc/letsencrypt/live/yourserver.example.com/cert.pem > /opt/pihole/letsencrypt/fullchain.pem
/usr/bin/docker-compose -f /opt/pihole/docker-compose.yaml down &>/dev/null
/usr/bin/docker-compose -f /opt/pihole/docker-compose.yaml up --detach &>/dev/null

And make it executable

sudo chmod +x /etc/letsencrypt/renewal-hooks/post/redeploy-docker.sh

This will copy the new certificate in to the correct folder and ensures, the docker container es restarted, so it will have the new ceritificate.

You can test whether your script works properly with a dry-run

sudo certbot renew --dry-run

If docker ps shows a new container id after that, the container was restarted successful.

With sudo openssl x509 -noout -text -in /opt/letsencrypt/combined.pem | grep Validity -A3 you will see, whether the new certificate was copied correctly (doesn't really work shortly after the installation, because you have no new certificate)

Usage

Now you can use the IP address of yourserver.example.com as you DNS server address.

You can now use https://yourserver.example.com/admin/ to check your server.

Connect with Android Keepass to Hetzner’s Storage Box

Connect with Android Keepass to Hetzner’s Storage Box published on

The goal is to connect Keepass2Android (used version 1.07b-r0) on Android to the Keepass database on a Hetzner Storage Box. In https://blog.chloesoe.ch/?p=546 it is described, how to connect and store your Keepass DB to the Storage Box.

Now we want to connect the mobile phone to that database.

  1. In Keepass Android choose "Open File" and then "SFTP (SSH File Transfer)"
  2. There you have to enter the connection details:
    1. Host: $USERNAME.your-storagebox.de
    2. Port: 23
    3. Username: Your user name ;-)
      4: Authentication mode: Privat/Public Key

      1. choose "Send public key". You could send it via e-mail; the public key is not sensitive. Make sure you send it somwhere, where you can access it like in https://blog.chloesoe.ch/?p=546 described.
      2. Save the public key to a file pubkey_android (you could change the key name at the end of the line of thet new file if you like).
      3. If you safed it like that, then you could run this:
        read -p "Enter your Hetzner's username: " USERNAME
        rsync --progress -e 'ssh -p23'  $USERNAME@$USERNAME.your-storagebox.de:.ssh/authorized_keys .
        cat pubkey_android >> authorized_keys
        rsync --progress -e 'ssh -p23'  authorized_keys $USERNAME@$USERNAME.your-storagebox.de:.ssh/
    4. Initial directory: /home
  3. Now you can connect and choose your Keepass database file.