Set Up Time Synchronization on Ubuntu with ntpd

Though timesyncd is fine for most purposes, some applications that are very sensitive to even the slightest perturbations in time may be better served by ntpd, as it uses more sophisticated techniques to constantly and gradually keep the system time on track.

sudo timedatectl set-ntp no
timedatectl
sudo apt-get install ntp
sudo ntpq -p

References

https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-16-04

Extra Repositories for Ubuntu Server 18.04

/etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu bionic universe multiverse
deb-src http://archive.ubuntu.com/ubuntu bionic universe multiverse

deb http://us.archive.ubuntu.com/ubuntu/ bionic universe
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic universe
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe

deb http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse

deb http://security.ubuntu.com/ubuntu bionic-security universe
deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse

References

https://help.ubuntu.com/lts/serverguide/configuration.html.en

Spring Boot: Configuring a Main Class

Spring Boot 1.x

jar {
    baseName = 'interface'
    version = '0.0.1-SNAPSHOT'
    manifest {
        attributes 'Main-Class': 'net.pupli.sobhan.SobhanApplication'
    }
}

Spring Boot 2.x

springBoot {
    mainClassName = 'org.baeldung.DemoApplication'
}

or

bootJar {
    mainClassName = 'org.baeldung.DemoApplication'
}
bootJar {
    manifest {
    attributes 'Start-Class': 'org.baeldung.DemoApplication'
    }
}

References

https://www.baeldung.com/spring-boot-main-class

Set Up SSH Keys on Ubuntu

Create the RSA Key Pair

ssh-keygen

Copy the Public Key to Ubuntu Server

cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"

or Copying Public Key Manually

To display the content of your id_rsa.pub key, type this into your local computer:

cat ~/.ssh/id_rsa.pub

You will see the key’s content, which should look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqql6MzstZYh1TmWWv11q5O3pISj2ZFl9HgH1JLknLLx44+tXfJ7mIrKNxOOwxIxvcBF8PXSYvobFYEZjGIVCEAjrUzLiIxbyCoxVyle7Q+bqgZ8SeeM8wzytsY+dVGcBxF6N4JS+zVk5eMcV385gG3Y6ON3EG112n6d+SMXY0OEBIcO6x+PnUSGHrSgpBgX7Ks1r7xqFa7heJLLt2wWwkARptX7udSq05paBhcpB0pHtA1Rfz3K2B+ZVIpSDfki9UVKzT8JUmwW6NNzSgxUfQHGwnW7kj4jp4AT0VZk3ADw497M2G/12N0PPB5CnhHf7ovgy6nL1ikrygTKRFmNZISvAcywB9GVqNAVE+ZHDSCuURNsAInVzgYo9xgJDW8wUw2o8U77+xiFxgI5QSZX3Iq7YLMgeksaO4rBJEa54k8m5wEiEE1nUhLuJ0X/vh2xPff6SQ1BL/zkOhvJCACK6Vb15mDOeCSq54Cr7kvS46itMosi/uS66+PujOO+xt/2FWYepz6ZlN70bRly57Q06J+ZJoc9FfBCbCyYH7U/ASsmY095ywPsBo1XQ9PqhnN1/YOorJ068foQDNVpm146mUpILVxmq41Cj55YKHEazXGsdBIbXWhcrRf4G2fJLRcGUr9q8/lERo9oxRm5JFX6TCmj6kmiFqv+Ow9gI0x8GvaQ== demo@test

make sure the ~/.ssh directory exists.This command will create the directory if necessary, or do nothing if it already exists:

mkdir -p ~/.ssh

Now, you can create or modify the authorized_keys file within this directory. You can add the contents of your id_rsa.pub file to the end of the authorized_keys file, creating it if necessary, using this command:

echo public_key_string >> ~/.ssh/authorized_keys

Finally, we’ll ensure that the ~/.ssh directory and authorized_keys file have the appropriate permissions set:

chmod -R go= ~/.ssh

Authenticate to Ubuntu Server Using SSH Keys

ssh username@remote_host

Disable Password Authentication on your Server

sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
sudo systemctl restart ssh

References

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1604

Change the encryption cipher for server and client of OpenVPN Access Server

cd /usr/local/openvpn_as/scripts

View current cipher configuration keys

./sacli ConfigQuery | grep "cipher"

Set the cipher configuration key to the desired cipher:

./sacli --key "vpn.client.cipher" --value AES-128-CBC ConfigPut
./sacli --key "vpn.server.cipher" --value AES-128-CBC ConfigPut
./sacli start

References

https://docs.openvpn.net/command-line/additional-security-command-line-options/#Change_the_encryption_cipher_for_server_and_client

Padding Strings with format method on Java

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s1 = sc.next();
    int x = sc.nextInt();

    PadLeft(s1);
    System.out.printf("%03d", x);
    System.out.println();

    PadRight(s1);
    System.out.printf("%03d", x);
}

private static void PadRight(String s)
{
    System.out.printf("%1$15s", s);
}

private static void PadLeft(String s)
{
    System.out.printf("%1$-15s", s);
}

15 represents the minimal width of the String

Input

Hello
12

Output

Hello          012
          Hello012

References
https://stackoverflow.com/questions/13475388/generate-fixed-length-strings-filled-with-whitespaces
http://www.rgagnon.com/javadetails/java-0448.html