Stoken: Alternative to RSA Secure ID Software to get random PIN

Hello Team,

Today Morning suddenly my Mac started giving trouble with RSA Secure ID software which we use to generate random OTP to connect with our secure VPNs. 

I am getting an error as below while launching RSA Secure ID



so I came across an alternative named stoken from my colleague. 

I have installed stoken using brew brew install stoken and imported my RSA Token file into stoken, and thats it, we are back with a terminal based Secure ID software which gives the token.

λ ~ ➤ stoken import -- file="/Users/xxxxx.xxxxxx/Desktop/xxxxx.xxxxxx_xxxxxxxx.sdtid"
Enter new password:
Confirm new password:
 λ ~ ➤ stoken
Enter password to decrypt token:
xxxxxx
    

Docker: Networking Basics - Configure static and Dynamic IP Address to Container

Hello Everyone, 

        In this post, I will show you how to create a network in the docker and how to spin containers with static IP and Dynamic IP Address. 

 

Step1: Create a new network for docker

You can create a new network in the docker using below command

 

docker network create --subnet=172.18.0.0/16 mydockernetwork

As network created just do docker inspect to make sure all good with it

~ docker network create --subnet=172.18.0.0/16 mydockernetwork
a4d11712754b7d5bf3ba25e3c831c8512065ce77a66099948effc59d5bae968f
~ docker inspect mydockernetwork
[
    {
        "Name": "mydockernetwork",
        "Id": "a4d11712754b7d5bf3ba25e3c831c8512065ce77a66099948effc59d5bae968f",
        "Created": "2021-08-07T11:27:38.515202386+05:30",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
] 

Step2: Lets spin a new container with dynamic IP

~ docker run --net mydockernetwork -it --name ubuntu_dynamic_ip3 ubuntu

By using docker inspect command lets extract IP Address of the above container.

 

~ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ubuntu_dynamic_ip3
172.18.0.2

 Step 3: Lets spin a new container with static IP

~ docker run --net mydockernetwork --ip 172.18.0.4 -it --name ubuntu_static_ip ubuntu
root@71f58fb557c1:/# %                                                                        ~ docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES
71f58fb557c1   ubuntu    "bash"    6 seconds ago   Up 5 seconds             ubuntu_static_ip
ab563564d964   ubuntu    "bash"    3 minutes ago   Up 3 minutes             ubuntu_dynamic_ip3
f4bc181d89af   ubuntu    "bash"    2 hours ago     Up 2 hours               ubuntu_container
~ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ubuntu_static_ip
172.18.0.4

 

Update #1: A Shell Function To Return Container IP Address.

As I have to get IP Address very often for different containers, I wrote a small function in bash which return IP Address of given container.

test_playbook git:(master)  function docker_ip
function> docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $1
test_playbook git:(master)  docker_ip webserver
172.18.0.5
test_playbook git:(master)  docker_ip mysql_db_ubuntu
172.18.0.4
test_playbook git:(master)  

 

You can add the function to your bashrc file and call the function any time. I use ZSH as my default shell, so I did as below

test_playbook git:(master)  vim ~/.zshrc       
test_playbook git:(master)  exec $SHELL
test_playbook git:(master)  docker_ip webserver
172.18.0.5
test_playbook git:(master)  tail -n 3 ~/.zshrc 

function docker_ip
  docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $1
test_playbook git:(master)  


Hope it helps.

Thank you.

How to take backup of your files regularly to external drive or to a new mount point ?

Hello Everyone,
As I have mentioned in other posts, I am using Arch based Endeavour distro in my ThinkPad.
No matter how stable the OS is, its always recommended to backup your important data.
So by doing very small tasks I achieve something like regular backup and OnDemand backup in my Arch Linux.

Step 1: Identify What folder you like to backup


So just to avoid any crazy permission related issues I got, like mentioned here , I set myself to use my home folder only for learnings.
So I have created a folder called `my_learning` and I am going to keep all my notes, code at that location. So if you want to create a folder you can simply do

mkdir ~/my_learning

Step 2: Install rsync ( If not installed )

If you dont know what rsync from Wikipedia

rsync is a utility for efficiently transferring and synchronizing files between a computer and an external hard drive and across networked computers by comparing the modification times and sizes of files


so what ever the distro you are using the binary name stays same to install rsync.
RedHat/CentOS/Fedora

sudo yum install rsync


Debian/Ubuntu

sudo apt-get install rsync


Arch

sudo pacman -S rsync


Step 3: Lets identify what Rsync options needed

So We need to backup to be happen in recusrive order and while its happening I need compress to happen just to save sometime. And verbose and human readable output format and pretty much needed anyway. So overall I need below options

-r, --recursive             recurse into directories
-z, --compress              compress file data during the transfer
-v, --verbose               increase verbosity
-h, --human-readable        output numbers in a human-readable format


But Rsync isnt limited to jus these 4 options, if you want to know more about rsync options, please check out its man page.

Step 4: source and target locations


So In one of my mount point I have created a folder with same name as source( make sure its mounted before creating the folder)
mkdir /run/media/username/ContinousImprovement/my_learning
.
and source is anyway my home folder
my_learning
location.
And the syntax of rsync is similar to cp command in linux i.e
cp [OPTIONS] source destination

rsync -zrvh /home/username/my_learning /run/media/username/ContinousImprovement/my_learning

Step 4: lets make the command handy

So I am using ZSH as my default shell, so I have opened my
.zshrc
file. If you are using bash, you can use
.bashrc
and I have added below function using shell scripting at very bottom

# backup home directory
function backup_home
  rsync -zrvh /home/username/my_learning /run/media/username/ContinousImprovement/my_learning


and execute
exec $SHELL
or
source ~/.zshrc
.
That's it, now if you call
backup_home
from terminal, your source directory will be backup to remote directory. if you want to automate it using a scheduler job, you can achieve same using
cron
, but make sure target is available during execution.
my_learning backup_home 
sending incremental file list
my_learning/ansible/ansible.cfg
my_learning/ansible/inventory
my_learning/ansible/test.yaml
...
...
...

sent 51.93M bytes  received 141 bytes  103.86M bytes/sec
total size is 55.07M  speedup is 1.06
my_learning 


Hope it helps.
Thank you.

Vagrant: How to provide custom SSH key location to solve chmod 600 error ?

Hello Everyone,
So today I am trying to spin a new vagrant instance from my Arch installation in a NTFS Partition.
So during `vagrant up` command, I got an error stating that it cant execute `chmod 600` command in my NTFS parition as my Vagrantfile located at my NTFS mount.
So on searching a bit, I came across custom SSH location config can be added to Vagrantfile as below

config.ssh.insert_key = false
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"


so my Vagrantfile config over looks like below

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.ssh.insert_key = false
  config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
end


And I have deleted the old vagrant machine with `vagrant destroy` command, and re provisioned the current vagrant machine with `vagrant up` and issue then I was able to SSH into the vagrant machine successfully with `vagrant ssh`.
Hope it helps.
Thank you.

What are the available Process Error Signals in Linux Kernel ?

As you all know like linux process uses error signals to communicate below is the list of errors 

Error Signal Description
{{key}} {{value}}