Categories
Linux Networking

hash known_hosts in Linux

When using SSH to connect to other hosts a file containing the accepted public keys is saved in your home directory, especially ~/.ssh/known_hosts. This file contains beside the public key the IP / Hostname of the connected servers. These informations can be critical, if any other program or user will read the known_hosts file. One way to protect these informations is to hash the IP / Hostname part of the file.

To activate SSH to do this, is to add the following config entry into your ssh config. If you cannot add it system wide you can use your local ssh config file: ~/.ssh/config

HashKnownHosts yes

You can use the following command to achieve this.

echo "HashKnownHosts yes" >> ~/.ssh/config

Now SSH client will hash newly generated entries automatically. To update all given entries you should run:

ssh-keygen -H -f ~/.ssh/known_hosts

Then check if the conversion was successful and after that delete the old file:

rm ~/.ssh/known_hosts.old

Categories
Linux

convert Markdown files to PDF in Ubuntu

I love it writing short and medium notes in Markdown. For printing or sharing with others I often use the PDF format.

To convert Markdown files into other formats, like PDF, HTML, etc., you can use pandoc.

Using Latex

Installation in Ubuntu

For installation just install package pandoc. For PDF conversion you need some latex packages too.

sudo apt install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra pandoc

Conversion to PDF

To convert your markdown file test.md into test.pdf you need to run the following command:

pandoc -t latex -o test.pdf test.md

Sometimes I had some problems with “complex” markdown files. Especially if i use nested ordered / unordered lists. One solution is to use the html5 engine of pandoc.

Using HTML

Currently this is my preferred way for conversation, because it is more stable. You can also setup some styling with a simple CSS file.

Installation in Ubuntu

For installation just install package pandoc and the rendered wkhtmltopdf.

sudo apt install wkhtmltopdf pandoc

Conversion to PDF

Now it is like the usage of latex, but with a small different parameter (example is with paper size A4):

pandoc -t html5 -V papersize=a4 -o test.pdf test.md

Further variables can be read in the manual of pandoc.

Categories
Linux

Modify screen resolution or dpi in display manager like gdm or lightdm

If you have a screen with a large resolution (for example 4k) or you have a high DPI (HiDPI) screen, you will know that the display manager uses a lower resolution or a wrong DPI setting.

The solution is very easy. As gdm or lightdm also have a normal user account with normal home directory. So you can just copy your correct monitors.xml to the home directory of your display manager. For gdm this would be:

sudo mkdir -p ~gdm/.config
sudo chown gdm:gdm ~gdm/.config
sudo cp -a  ~/.config/monitors.xml ~gdm/.config/
sudo chown gdm:gdm ~gdm/.config/monitors.xml

After reboot you will see the correct screen resolution.

This is especially useful on HiDPI changes, because GNOME Shell in Manjaro (ArchLinux) makes all windows small on screen lock, so that you have to resize them after relogin.

Categories
Linux Networking

Optimize CIFS mounts for slow connections in Linux

With the default settings on mounting CIFS I had the problem while uploading a large file (200 – 300 MB) that my system frozen for some seconds. Additionally progress bars in Midnight Commander for example filled up to 100 % in some milliseconds and then it took 5 till 10 minutes until the copy job was finished.

The reason for this was that the dirty block cache of the Linux Kernel was filled by the copy job and sometimes was also full and could only cleared slowly, because of the slow connection to the server.

You can watch the current state of the dirty_cache with:

watch -n 2 "cat /proc/meminfo | egrep -i 'dirty|write'"

Also you can adjust the dirty_background_bytes and dirty_bytes of the kernel, but these settings are system wide and not only for a mountpoint. So you need more cache for local storage to get things fast and small cache for slow remote operations. But you should check the following settings of your kernel:

  • vm.dirty_background_bytes
  • vm.dirty_bytes
  • vm.dirty_expire_centisecs
  • vm.dirty_writeback_centisecs

There are many different “best values” found on the internet, but it depends. So I will not add more here.

Sometimes I also get some errors (Error 4 and Error 5), I assume due to timeouts or thatever, after the copy job was finished. Also in kernellog the following entries was reported:

CIFS VFS: No writable handles for inode<br>CIFS VFS: cifs_invalidate_mapping: could not invalidate inode

To solve the problem with the cifs mount, one solution is to disable the cache of this mount. You can do it with the mount option cache=none of mount.cifs.

The upload is a little bit slower, but it is stable now.

Categories
Linux

distorted sound in Ubuntu

In some constellations I use Ubuntu with HDMI output. Sometimes I had some problems using sound output via HDMI. These were distorted sound with scratches and echoes. Sometimes it hides after some seconds or minutes and sometimes I had to reboot.

I used then pavucontrol (install via apt install pavucontrol) to check the settings. This application is very nice, because you can see which application is using the sound output and you can adjust the volume per application.

The application showed me multiple processes of speech-dispatcher using my sound card. After i muted these application instances, the distorted sound was gone.

But what is speech-dispatcher? Speech-dispatcher is a server for text to speech. Some applications like Firefox seems to use it. For me I don’t need text to speech, so I uninstalled the package.

apt purge speech-dispatcher

For those who need it, there is also a related issue in Ubuntu’s bug tracker with some alternative solutions or workarounds.