Tag Archives: linux

Get the nth element of a csv file in Linux

You have a file called input.csv file containing

fname, lname, email, postcode

john,smith,johnsmith@example.com,4000

jane,doe,janedoe@example.com,4112

 

and you want to get the lname element

while IFS=',' read -r a1 a2 a3 a4 
do 
echo "$a2" >> lname.csv
done < input.csv

Source: https://unix.stackexchange.com/questions/106047/extract-the-4th-column-from-a-csv-file-using-unix-command

Add storage and format disk in Debian

sudo fdisk -l
# take note of the added disk
sudo fdisk /dev/sdX
# where X is the value for the disk

# in fdisk:
n (ew)
p (rimary)
1
(first and last sector defaults)
w (rite)

sudo fdisk -l
# take note of disk partition, eg: sdX1
sudo mkfs -t ext4 /dev/sdX1

sudo mkdir /mnt/newdisk
lsblk -d -fs /dev/sdX1
# take note of UUID value
# edit /etc/fstab to add the following
UUID=$UUIDValueFromAbove /mnt/newdisk ext4 defaults 0 2

sudo mount -a
# or reboot to test

References:

https://linuxconfig.org/how-fstab-works-introduction-to-the-etc-fstab-file-on-linux

https://linuxconfig.org/how-to-add-new-disk-to-existing-linux-system

xrdp on Kali

apt-get update
apt-get full-upgrade -y
apt-get install -y kali-desktop-xfce xorg xrdp
echo "[i] Configuring xrdp to listen to port 3390 (but not starting the service)"
sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini
sudo /etc/init.d/xrdp start
sudo systemctl enable xrdp

Access it from MS RDP using port 3390 (it translates to 3389 – see the line with sed to change)

 

from https://www.kali.org/docs/general-use/xfce-with-rdp/

 

Enabling SSH on Kali

This will probably work for other distributions as well.  Be aware this enables password auth.

apt install openssh-server
mkdir /etc/ssh/defaultkeys
mv /etc/ssh/ssh_host_* /etc/ssh/defaultkeys/
dpkg-reconfigure openssh-server
systemctl enable ssh.service
systemctl start ssh.service
systemctl status ssh.service

 

Edit /etc/ssh/sshd_config

and the following:

PubkeyAuthentication yes

PasswordAuthentication no

To use key based authentication.

Adding a new disk to an LVM with esx

$ lsblk

Look at disks to check what is already in use

Add disk in vcenter

$ for h in $(ls /sys/class/scsi_host); do

echo ‘- – -‘ > /sys/class/scsi_host/$h/scan
done

$ for h in $(ls /sys/class/scsi_host); do
    echo '- - -' > /sys/class/scsi_host/$h/scan
done
$ lsblk

look at disks, it should be added

fdisk -l

take note of added disk

eg: /dev/sdc

fdisk /dev/sdc
n - new partition
p - primary
1
defaults
w - write
pvscan

take note of disk /dev/sdc1

pvcreate /dev/sdc1
vgdisplay

take note of vg name, eg: ubuntu-vg

vgextend ubuntu-vg /dev/sdc1
pvscan

disk should be added

lvdisplay

take note of LV name (logical volume name), eg: /dev/ubuntu-vg/ubuntu-lv

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
resize2fs -p /dev/ubuntu-vg/ubuntu-lv

Upgrading Debian Buster to Bullseye

sudo apt update
sudo apt -y remove apt-listchanges
sudo apt -y upgrade
sudo apt -y full-upgrade
sudo apt -y autoremove
sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list
sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list.d/*.list
sudo sed -i 's#/debian-security bullseye/updates# bullseye-security#g' /etc/apt/sources.list
export LC_ALL=C 
sudo apt update
sudo apt -y upgrade
sudo apt -y full-upgrade
sudo apt -y autoremove

References: https://linuxize.com/post/how-to-upgrade-debian-10-to-debian-11/

 

Prevent apt-get upgrade from showing the change log

I was scheduling an apt-get update && apt-get –y upgrade on a Debian 8 box and the process stopped waiting for keyboard input showing the change logs for CA-Certificates.

it had actually started VI and was displaying a text file.  This would stop the automatic update process.

To prevent this I ran apt-get –y remove apt-listchanges

References:

https://serverfault.com/questions/835303/is-there-a-way-to-make-apt-get-upgrade-not-show-changelogs