CategoryUbuntu

Blurry vscode and chrome browser in Ubuntu 22.04

I recently bought a new laptop and installed a fresh Ubuntu! (Ubuntu 22.04.1 LTS). But due to Wayland the Electron apps (in my case Chrome and VSCode) do not support scaling.

I often search for fixes online, but could not find a fix at first. But a week later I fortunately stumbled upon the answers!

Chrome

The fix for chrome is to install the unstable version:

sudo apt install google-chrome-unstable

And alter the desktop launch file to make sure it starts with the arguments as provide in this post:

sudo code /usr/share/applications/google-chrome-unstable.desktop

Make sure the execute reads the following:

Exec=/usr/bin/google-chrome-unstable %U -enable-features=UseOzonePlatform -ozone-platform=wayland

Visual Studio Code

For vscode we follow a similar approach, but we do not have to install an unstable version. Open the desktop file.

sudo code /usr/share/applications/code.desktop

Make sure the execute line under [Desktop Entry] reads:

Exec=/usr/share/code/code --unity-launch %F --enable-features=UseOzonePlatform --ozone-platform=wayland --log debug

And under [Desktop Action new-empty-window] reads:

Exec=/usr/share/code/code --new-window %F --enable-features=UseOzonePlatform --ozone-platform=wayland --log debug

I often start vscode from a terminal, and that has not the arguments that we added in the *.desktop files by default. Therefore I created an alias in my ~/.zshrc (Yes, I used zsh).

alias code='f() {/usr/bin/code $@ --enable-features=UseOzonePlatform --ozone-platform=wayland};f'

now, when launching code it launches it with the correct parameters.

Last step is to fix the titlebar again, in vscode:

ctrl + shift + p

Open the settings in JSON and add:

"window.titleBarStyle": "custom"

Increasing RAM with SWAP partition

When building large projects with Yocto/Bitbake I encountered hangups of my host OS due to lack of RAM space.

The solution to that was creating a SWAP partition, which actually allocates space on a SSD (preferably) or a HDD. Note that a HDD and SSD are always slower than RAM, but better than having hangups.

How to create a swapfile on Ubuntu 18.04 (may work on other distros as well). Replace <user> with your local user (echo $USER).

  1. Create a swap file with dd. I generally double my RAM capacity, so I choose my swapfile to be the same size as RAM on my system.
# bs=1G and count=4 -> 4GB swapfile
$ dd if=/dev/zero of=/home/<user>/swapfile bs=1G count=4

2. Set correct permission on the swapfile

$ sudo chmod 600 /home/<user>/swapfile

3. Make ‘swapfile’ usable as swap

$ sudo mkswap /home/<user>/swapfile

4. Tell the OS to use the swapfile

$ sudo swapon /home/<user>/swapfile

In principle you are done. The OS is using your swapfile. However it is not acitivated on a restart of your OS. To fix that we have to add it to the fstab file.

5. Add the following line to the /etc/fstab

/home/<user>/swapfile none swap sw 0 0

Check with “top”, “htop”, or even “bashtop” your new physical memory size!

Finally, you’d like not to use the swapfile if it is not necessary. You can specify the “swappiness” for that.

# 0 = disable swap, 100 = swap as much as possible
$ sysctl vm.swappiness=10

Sources:
[1] https://help.ubuntu.com/community/SwapFaq

Get notified on a SSH login

Of course nobody should be able to login to your server. But if someone finds a way to do it, don’t you want to know it?

I am running an Ubuntu Server that uses motd to welcome logged in users. Therefore I am using motd to execute a script for me once a user logged in.

I extracted the details of the just logged in user from /var/log/auth.log, and uses the IP address and a resolver (ipapi.co in my case) to resolve the IP address to a location.

I am using a Telegram Chat with my own Telegram bot to notify me. I might write a small blogpost about my Telegram bot in the future.

Place the script in a file, make it executable, and place it in /etc/update-motd.d/. For example:

$ touch /etc/update-motd/01-notify-me.sh
$ chmod +x /etc/update-motd/01-notify-me.sh
$ vi /etc/update-motd/01-notify-me.sh # Add script 

And the actual script:

#!/bin/bash

_loginDetails=$(grep "Accepted" /var/log/auth.log | tail -n 1)
_IP=$(echo $_loginDetails | awk '{print $11}')
_LOCATION=$(curl https://ipapi.co/${_IP}/json/ | jq .city -r)
_METHOD=$(echo $_loginDetails | awk '{print $7}')
_WHO=$(echo $_loginDetails | awk '{print $4}')
message="[SSH LOGIN] => ${_WHO} from ${_LOCATION}, IP: ${_IP}, AUTH: ${_METHOD}"

curl -s -X POST https://api.telegram.org/<bot_token>/sendMessage -d chat_id=<chat_id> -d text="${message}"

Additional security measures should be taken, for example:

  • Login with Key only
  • Disallow root login via ssh
  • Blacklist IP’s
  • Block based on Geo location
  • fail2ban

© 2025 Roholt

Thema door Anders NorénOmhoog ↑