Ubuntu 18.04 Server – Set Static IP With Netplan

sudo vim /etc/netplan/01-netcfg.yaml
network:
    ethernets:
        eno1:
            addresses:
            - 172.20.63.234/24
            - 192.168.10.20/24
            - 192.168.1.240/24
            dhcp4: false
            gateway4: 172.20.63.254
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
        enp3s0:
            addresses: []
            dhcp4: true
            optional: true
    version: 2

Testing the Configuration

sudo netplan try

Applying the New Configuration

sudo netplan apply

References
https://blog.programster.org/set-static-ip-with-netplan
https://www.linux.com/learn/intro-to-linux/2018/9/how-use-netplan-network-configuration-tool-linux

Set Up SSH Keys on Ubuntu

Create the RSA Key Pair

ssh-keygen -t rsa -b 4096 -C "[email protected]"

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

or Copy using ssh-copy-id

ssh-copy-id [email protected]
ssh-copy-id [email protected] -p 22000
ssh-copy-id -i id_rsa.pub -p 22000 "[email protected]"

use -i identity_file for other identities

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

Convert private key to putty 

puttygen keyname -o keyname.ppk

ssh “permissions are too open” error

Keys need to be only readable by you:

chmod 400 ~/.ssh/id_rsa

If Keys need to be read-writable by you:

chmod 600 ~/.ssh/id_rsa

References
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1604
https://haydenjames.io/how-to-convert-openssh-keys-to-putty-ppk-on-linux-with-puttygen/
https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error

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