Sunday, July 11, 2021

Setup an openssh-server in a docker container

This is mainly used for testing only. 

First create a Dockerfile. I am using ubuntu:20.04 image for this

$ cat >> Dockerfile <<EOF

FROM ubuntu:20.04

RUN apt update && apt install openssh-server -y

RUN useradd myuser && echo "myuser:123456" | chpasswd && echo "root:123456" | chpasswd && mkdir /run/sshd


CMD /usr/sbin/sshd -D


Then, build the image

$ docker build -t mysshimage .

Finally, run a container based on the image, and ssh into it. Use 123456 as password.

$ docker run -dit -p 1022:22 mysshimage

$ ssh myuser@localhost -p 1022 

To be a root user, just use su - command once you are logged in as myuser.

Monday, July 5, 2021

Combining pdf files in linux

One of the tool I always use to combine pdf file, is pdftk.

To install pdftk, just run apt install

$ sudo apt update && sudo apt install pdftk -y

To combine pdf files into one:

$ pdftk file1.pdf file2.pdf file3.pdf cat output combined.pdf

where file1.pdf , file2.pdf and file3.pdf are the outputs, and the combined.pdf is the result after the combination process.

Thursday, July 1, 2021

Git clone over ssh socks proxy

This is useful for a machine that needs to clone some repository from github, but does not having internet connection.

First, we must identify another machine that can access, we can call this server proxy-server.

Then, establish a socks proxy from our no-internet-server
$ ssh -qN -D 1234 proxy-server

The above command will create a socks proxy at localhost port 1234

Use the git command with socks proxy. Let's say we want to clone the 30-seconds-of-code repository, run below command in a new shell
$ git -c http-proxy=socks5h://localhost:1234 clone

Once done, press ctrl-c in the first shell, to terminate the socks proxy

Tuesday, June 29, 2021

Converting putty formatted ppk private key into ssh formatted private key

Putty used different format of private key compared to openssh. To use putty private key (usually with .ppk extension) with openssh, we need to convert it into openssh formatted private key.

To do this, we need putty tools. To install putty tools:

# apt install putty-tools -y

To convert, just use a command called puttygen, which is part of the putty-tools package

# puttygen myprivatekey.ppk -O private-openssh -o myprivatekey.priv

whereby myprivatekey.ppk is the private key in putty format, -O is to specify what output type we want puttygen to produce and -o is to specify the output file.

Once produced, we can test the private key using ssh command

# ssh myuser@myserver -i myprivatekey.pem

Saturday, June 26, 2021

Adding custom nameserver in systemd-resolve

The old /etc/resolve is now being managed by systemd-resolve service, which is part of systemd. In order to add new nameserver, please follow below steps

1. Create a directory named /etc/systemd/resolved.conf.d/

# mkdir /etc/systemd/resolved.conf.d

2. Add a new configuration file for your new dns server. Let's say we want to add google's dns ip address, which are and 

# cat >> /etc/systemd/resolved.conf.d/mynameserver.conf <<EOF




3. Restart the service

# systemctl restart systemd-resolved

4. Verify that your dns is now being used by the system

# systemd-resolve --status


       LLMNR setting: no                  

MulticastDNS setting: no                  

  DNSOverTLS setting: no                  

      DNSSEC setting: no                  

    DNSSEC supported: no                  

         DNS Servers:             



For more information about what option can be included in the configuration file, please refer to resolved.conf man page.