Monday, January 13, 2025

nvme with Linux

Solution to OS lockup issue on nvme with Linux:

$ sudo vim /etc/default/grub

## append to GRUB_CMDLINE_LINUX=""
nvme_core.default_ps_max_latency_us=0
$ sudo update-grub
 
## suppress bios firmware related error: loglevel=3 
 

Sunday, May 12, 2024

Azure Tools in Linux

In Linux/WSL2, configuring azure swa and cli tools for deployment of Single-Web-App.

Installing swa-cli and env-cmd commands:

$ sudo npm install -g @azure/static-web-apps-cli
$ sudo npm install -g env-cmd

$ swa login --no-use-keychain 
$ export SWA_CLI_DEPLOYMENT_TOKEN=xxxyyyzzz
$ swa deploy ./build --env production --no-use-keychain

 

Installing Azure CLI tools, source Install the Azure CLI on Linux:

$ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash 

$ az login

Sunday, January 14, 2024

RPi - raspberry pi

 add wifi network:

$ sudo iwlist wlan0 scan

$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

 network={
  ssid="wifiName"
  psk="wifiPassword"
}

 

 

Tuesday, September 12, 2023

NodeJS

 Installing nodejs 18 in Ubuntu/Debian.


$ vim install_node.sh
 
sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=18
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg]  https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install nodejs=18.17.1-1nodesource1 -y
 

Saturday, June 17, 2023

SSH Agent

To Start the ssh-agent on opening new terminal (Linux or WSL2).

Add following lines to ~/.bash_aliases

 
export SSH_AUTH_SOCK="${HOME}/.ssh/ssh-agent.sock"
ssh-add ~/keys/git-rsa
 
if [ $? -ge 2 ];then
    ssh-agent -a ${SSH_AUTH_SOCK}
    ssh-add ~/keys/git-rsa
fi

It will start the ssh-agent if it is not already running or else connect to existing ssh-agent for new terminal.

 

Tuesday, January 17, 2023

Podman in WSL2

For Debian 11 distro in WSL2, following are the commands to install podman (v3.0.1) and configuring it in order to avoid error during execution of podman commands. As in WSL2 there is no systemd so need to update 'cgroup_manager' and 'event_logger'.

 

$ sudo apt-get install podman

$ sudo vim /etc/containers/registries.conf

unqualified-search-registries = ["docker.io"]

 

$ sudo cp /usr/share/containers/containers.conf ${HOME}/.config/containers/libpod.conf 

[engine]
cgroup_manager = "cgroupfs"
events_logger = "file"
 

$ sudo cp ${HOME}/.config/containers/libpod.conf /etc/containers/containers.conf

 

For running Flask application in container, use tiangolo/uwsgi-nginx:python3.8 as base image hosted on docker.io. 

 

$ podman build -t test02

$ podman run --rm --name tester -p 8080:80 localhost/test02

 

Since by default, podman is not allowed to run container on privileged ports like 80, in above example running it on 8080 or else need to edit sysctl.conf

 

$ sudo vim /etc/sysctl.conf

net.ipv4.ip_unprivileged_port_start=0

$ sudo sysctl -p    # to apply changes


It can be accessed from web-browser on host as http://localhost:8080

 

For error "/" is not shared mount:

$ findmnt -o PROPAGATION /
PROPAGATION
private
$ uname -r
5.10.16.3-microsoft-standard-WSL2 
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy
 
# add in /etc/rc.local or /etc/rc.conf 
$ sudo mount --make-rshared / 

 

$ sudo usermod --add-subuids 10000-75535 USERNAME
$ sudo usermod --add-subgids 10000-75535 USERNAME 

 

Tuesday, July 5, 2022

gEdit via rdesktop

 gedit via rdesktop unable to change the preference, this is valid if installed in wsl2 on Windows 11 (that support WSLg).

In such cases we can change the gEdit settings via terminal using gsettings command. Following command will output all the available keys in all schemas.


for example,

gsettings list-recursively | grep 'org.gnome.gedit.preferences.editor'

  • schema:  org.gnome.gedit.preferences.editor
  • key      :  insert-spaces
  • value   :  true

It is useful to quickly set up gedit on newly installed machine by keeping settings in a bash shell scrip and execute it. Here is my custom gedit settings.

Sunday, February 7, 2021

VPN: OpenConnect

For connecting to vpn using openconnect command, we need to install three packages:

  • openvpn
  • easy-rsa
  • openconnect

 

In RedHat or CentOS based Linux system:

  • $ sudo yum install epel-release                            
  • $ sudo yum install -y openvpn easy-rsa
  • $ sudo yum install -y openconnect

 

In Debian based Linux system:

  • $ sudo apt install -y openvpn easy-rsa
  • $ sudo apt install -y openconnect

 

Before connecting to vpn, create tunneling device using openvpn command and make it active. If 'ip' command is not available (on older system) use "sudo ifconfig tun1 up" in step 2

  • $ sudo openvpn --mktun --dev tun1
  • $ sudo ip link set tun1 up
  • $ sudo openconnect <IP-Address> --interface=tun1

Once done, remove the tun1 using following commands:

  • $ sudo ip link set tun1 down
  • $ sudo openvpn --rmtun --dev tun1


Friday, March 8, 2019

ASUS e203MAH


Entering Bootloader of ASUS E203 MAH laptop:
  1. Power on the Asus S200e laptop
  2. Press and hold F2 key when powering on the Asus S200e laptop to enter the bios.
  3. Switch to the “Boot” tab and set “Launch CSM” to Enabled.
  4. Switch to the “Security” tab and set “Secure Boot Control” to Disabled.
  5. Press F10 to save and exit.
  6. Press and hold ESC key to launch the boot menu while the Asus S200e laptop is powering up.
source: https://www.rgb.ie/2015/03/26/how-to-boot-from-usb-drive-on-a-asus-s200e-laptop/
 

Friday, January 18, 2019

Python3 on CentOS 7

  • yum -y install https://centos7.iuscommunity.org/ius-release.rpm
  • yum -y install python36u
  • yum -y install python36u-pip
  • yum -y install python36u-devel

 

Create python3 virtual environment:

  • python3.6 -m venv myWorkEnvironment
  • source myWorkEnvironment/bin/activate
 

Note: python3 is now available by default distros repository and no need to install iuscommunity. Its available directly "sudo yum install -y python3"

Thursday, May 24, 2018

Raspberry Pi 3 - Led status


cat /sys/class/leds/led0/trigger
none rc-feedback kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu cpu0 cpu1 cpu2 cpu3 default-on input panic mmc1 [mmc0] rfkill-any rfkill0 rfkill1

echo none > /sys/class/leds/led0/trigger
will turn off the led completely (if it becomes annoying)

echo heartbeat > /sys/class/leds/led0/trigger
will cause the led to flash with the linux heartbeat pattern

echo timer > /sys/class/leds/led0/trigger
will cause the led to flash once a second

Friday, October 13, 2017

BerryBoot


Default cmdline.txt

elevator=deadline quiet bootmenutimeout=10


Parameter setting for config.txt

hdmi_force_hotplug=1
hdmi_drive=2
hdmi_group=2
hdmi_mode=81

.

Friday, July 7, 2017

RPI 3 - check temperature


On the raspberry pi 3 for checking temperature of CPU core there are two ways.
First method if you are running official raspbian, second method for any other Linux distro like Kali

Method I:
$ vcgencmd measure_temp
output:
temp=45.1'C

Method II:
$ cat /sys/class/thermal/thermal_zone0/temp
output:
45084

Both are reading 45 degree Celsius


=> turn HDMI off to reduce current requirement

to turn off:
/opt/vc/bin/tvservice -o

to turn on
/opt/vc/bin/tvservice -p


Saturday, November 5, 2016

Kali Copy/Paste not working in VMware Workstation 12


solution found on following url 
http://securityblog.gr/3229/cannot-copypaste-on-kali-and-vmware-workstation-12/



1. uninstall vmware-tools (if installed)
$ sudo /usr/bin/vmware-uninstall-tools.pl

2. Install VM Tools
$ sudo apt-get install open-vm-tools 
$ sudo apt-get install open-vm-tools-desktop 

3. restart Kali 
$ sudo init 6
 

Friday, September 9, 2016

Set locale environment variable

 
$ more /etc/sysconfig/i18n 
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
 
For Kali Linux:
echo "export LANG=\"en_US.UTF8\"" >> .bashrc 
 
Note: .bashrc will be read everytime upon opening a new terminal. 



Tuesday, April 26, 2016

HDMI output issue with Raspberry Pi 3

You need to edit /boot/config.txt file in order to enable HDMI forcefully ie even if no display is connected.
  hdmi_force_hotplug=1
  hdmi_drive=2
  hdmi_group=2
  hdmi_mode=81 


the second entry 'hdmi_drive=2' force HDMI mode rather than DVI, this makes audio works in DMT (computer monitor).

complete file config.txt

The 64 MB partition of the SD-card is mounted as /boot when OS is booted and running.


hdmi_drive=1 Normal DVI mode (No sound)
hdmi_drive=2 Normal HDMI mode (Sound will be sent if supported and enabled)

hdmi_group=1 CEA # TV
hdmi_group=2 DMT # Computer monitor
 
hdmi_mode=81 1366x768 60 Hz

New User add in Kali linux


To add new user in Kali (with root user):
  useradd -m username
  passwd username
  usermod -a -G sudo username
  chsh -s /bin/bash username


To set timezone:
  echo "TZ=Asia/Kolkata;export TZ" >> .profile

On Raspberian:
  sudo cp /usr/share/zoneinfo/Asia/Kolkata /etc/timezone
   

Monday, December 7, 2015

Portals for fetching open data

[From Open Source For You - November 2015 issue]

Datahub:
http://datahub.io

World Health Organisation:
http://www.who.int/research/en  - not available

The World Bank:
http://data.worldbank.org

NASA:
http://data.nasa.gov

United States Government:
http://www.data.gov



Monday, March 3, 2014

Compressing using bz2 library in C++



For Compiling:
$ g++ code.cpp -lbz2
 

Need to open two FILE*
one to read from and second to write compressed data 

#include <bzlib.h>

int bzerror = BZ_OK;
BZFILE *bfp = BZ2_bzWriteOpen(&bzerror, fpout, 9, 0, 30);
if (bzerror != BZ_OK)
{
    BZ2_bzWriteClose(&bzerror, bfp, 0, NULL, NULL);
    fclose(fpin);
    fclose(fpout);
    return 1;
}

memset(buf, 0, nBuf);
while (fgets(buf, nBuf, fpin) != NULL)
{
    len = strlen(buf);
    BZ2_bzWrite(&bzerror, bfp, buf, len);
    if (bzerror == BZ_IO_ERROR)
    {
        std::cout << "bz-io-error detected\n";
        break;
    }
    memset(buf, 0, nBuf);
}
BZ2_bzWriteClose(&bzerror, bfp, 0, NULL, NULL);

// ---- end ----


BZFILE *BZ2_bzWriteOpen( int *bzerror, 
                                                   FILE *f, 
                                                   int blockSize100k, 
                                                   int verbosity, 
                                                   int workFactor );

- blockSize100k specifies the block size to be used for compression
- verbosity should be set to a number between 0 and 4 inclusive. 
  0 is silent, and greater numbers give increasingly verbose monitoring/debugging output 
- workFactor controls how the compression phase behaves when presented with worst case,   highly repetitive, input data. 
  If compression runs into difficulties caused by repetitive data,the library switches from the standard sorting algorithm to a fallback algorithm. 
  The fallback is slower than the standard algorithm by perhaps a factor of three, but always behaves reasonably, no matter how bad the input


=====================================

Reading Compressed file ie Extracting Data

#include <bzlib.h>

int nBuf = 512;
memset(buf, 0, nBuf);

bzerror = BZ_OK;
while (bzerror == BZ_OK)
{
    BZ2_bzRead(&bzerror, bfp, (char*)buf, nBuf);
    if (bzerror == BZ_IO_ERROR)
    {
        std::cout << "bz-io-error detected\n";
        break;
    }
    std::cout << buf;
    memset(buf, 0, nBuf);
}
BZ2_bzReadClose(&bzerror, bfp);
fclose(fpin);

// ---- end ----




BZFILE *BZ2_bzReadOpen(int *bzerror, 
                       FILE *f, 
                       int verbosity, 
                       int small, 
                       void *unused, 
                       int nUnused );

- If small is 1, the library will try to decompress using less memory, at the expense of speed.
- decompress the nUnused bytes starting at unused

Tuesday, September 11, 2012

URL Decode in C ( http query string )

/*

* to decode http query_string ie to convert special characters in
* Query String to their original form like %20 to space %22 to  
* double-quote
*
* if 'str' contains  type=it%20is%20simple%20%22text%22
* ie when called as
* http://localhost/cgi-bin/a.out?type=it is simple "text"
* 
* when used as cgi-bin with apache
* 
* NOTE:
* for GET method there is environment variable set by apache QUERY_STRING
* for POST method, need to read from STDIN 
*
*/ 

int urlDecode(char *str);

int main(int argc, char *argv[])
{
    char *query_string;
    printf("Content-type: text/html\r\n\r\n"); /* required */
    query_string = getenv("QUERY_STRING");
    if (!query_string)
    {
        printf("QUERY_STRING not found\n"); return 1;
    }
    urlDecode(query_string);
    printf("text received: %s \n", query_string);
}

int urlDecode(char *str)
{
    unsigned int i;
    char tmp[BUFSIZ];
    char *ptr = tmp;
    memset(tmp, 0, sizeof(tmp));

    for (i=0; i < strlen(str); i++)
    {
        if (str[i] != '%')
        {
            *ptr++ = str[i];
            continue;
        }

        if (!isdigit(str[i+1]) || !isdigit(str[i+2]))
        {
            *ptr++ = str[i];
            continue;
        }

        *ptr++ = ((str[i+1] - '0') << 4) | (str[i+2] - '0');
        i += 2;
    }
    *ptr = '\0';
    strcpy(str, tmp);
    return 0;
}