Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

21 July 2015

Data Security: Cryptsetup

Data Security: Cryptsetup

Data Security: Cryptsetup

Cryptsetup

according to the MAN page:
cryptsetup - manage plain dm-crypt and LUKS encrypted volumes

..cryptsetup is used to conveniently setup dm-crypt managed device-mapper mappings. These include plain dm-crypt volumes and LUKS volumes. The difference is that LUKS uses a metadata header and can hence offer more features than plain dm-crypt...




• Installing Cryptsetup:
sudo apt install cryptsetup


***SETUP***

• Creating a container:
dd if=/dev/urandom of=~/my_encrypted_drive.dd bs=1M count=256

• Format it:
sudo cryptsetup luksFormat ~/my_encrypted_drive.dd

• Opening it:
sudo cryptsetup luksOpen ~/my_encrypted_drive.dd my_drive
my_drive will appear in /dev/mapper/.

• Create a filesystem within it:
mkfs -t ext4 /dev/mapper/my_drive

• Mount the container:
sudo mount -t ext4 /dev/mapper/my_drive ~/mnt/


***Consequence run***

sudo cryptsetup luksOpen ~/my_encrypted_drive.dd my_drive
sudo mount -t ext4 /dev/mapper/my_drive~/mnt/


• Unmounting:
sudo umount ~/mnt/
sudo cryptsetup luksClose my_drive


• Changing Password/Passphrase:
sudo cryptsetup luksChangeKey my_encrypted_drive.dd

• for more usage and help:
cryptsetup --help
man cryptsetup

Read more at Cryptsetup Homepage and Wikipedia .


note:
device => my_encrypted_drive.dd


Disclaimer

04 July 2015

Unix tricks: Create a Portable Drive

Unix Tricks: Create a Portable Drive

Create a Portable Drive
unix tricks

Unix Tricks

• Create a blank file of 256 MB :
dd if=/dev/zero of=~/portable.drive bs=1M count=256

• Create an ext4  filesystem within the file:
mkfs -t ext4 ~/portable.drive
you can replace ext4 with ext2, ext3, vfat, msdos, minix etc.

• Create a mount point:
mkdir ~/mnt/

• Mount the File/Drive:
sudo mount -t ext4 ~/portable.drive ~/mnt/
  ••Now you can browse the drive••

• Unmount the drive:
sudo umount ~/mnt/

    Advantages
  • Easy to carry files stored in one container.
  • Good for hiding data and files from plain sight.if you share your computer with others
  • Usable across unix System.
    Disadvantages
  • No security or encryption set/applied.
  • Cannot be viewed, opened in Windows natively.


note:
The file created by this method can only be open and read by unix and unix-like system. Natively Windows cannot open this kind of file. but its possible to open it with Cywin
software.

letter-spacing:1px; letter-spacing:1px; Disclaimer

11 April 2014

Cowsay

Fun with Cowsay
As per unix manual, Cowsay is a configurable speaking/thinking cow. Cowsay is fun and bring relief when working with commands become long.
whatis cowsay
cowsay (6) - configurable speaking/thinking cow (and a bit more)

# try out this few commands
cowsay hello
cowthink hello
fortune | cowsay
fortune | cowthink
# Using others figures:
cowsay -f /usr/share/cowsay/cows/elephant.cow hello
fortune | cowsay -f /usr/share/cowsay/cows/elephant.cow
-f  is a file argument. it point to a cow file. and
/usr/share/cowsay/cows/elephant.cow  is the cow file.

cowsay -f /usr/share/cowsay/cows/vader.cow "The Empire strikes back"


# Here are few customised alias to make it easier to use cowsay. append the code below into .bashrc .

.bashrc
#cowsay alias
cowfolder=/usr/share/cowsay/cows

alias aptsay='cowsay -f $cowfolder/apt.cow'
alias beavis.zensay='cowsay -f $cowfolder/beavis.zen.cow'
alias bongsay='cowsay -f $cowfolder/bong.cow'
alias bud-frogssay='cowsay -f $cowfolder/bud-frogs.cow'
alias bunnysay='cowsay -f $cowfolder/bunny.cow'
alias calvinsay='cowsay -f $cowfolder/calvin.cow'
alias cheesesay='cowsay -f $cowfolder/cheese.cow'
alias cocksay='cowsay -f $cowfolder/cock.cow'
alias cowersay='cowsay -f $cowfolder/cower.cow'
alias daemonsay='cowsay -f $cowfolder/daemon.cow'
alias defaultsay='cowsay -f $cowfolder/default.cow'
alias dragon-andsay='cowsay -f $cowfolder/dragon-and.cow'
alias dragonsay='cowsay -f $cowfolder/dragon.cow'
alias ducksay='cowsay -f $cowfolder/duck.cow'
alias elephantsay='cowsay -f $cowfolder/elephant.cow'
alias elephant-in-snakesay='cowsay -f $cowfolder/elephant-in-snake.cow'
alias eyessay='cowsay -f $cowfolder/eyes.cow'
alias flaming-sheepsay='cowsay -f $cowfolder/flaming-sheep.cow'
alias ghostbusterssay='cowsay -f $cowfolder/ghostbusters.cow'
alias gnusay='cowsay -f $cowfolder/gnu.cow'
alias head-insay='cowsay -f $cowfolder/head-in.cow'
alias hellokittysay='cowsay -f $cowfolder/hellokitty.cow'
alias kisssay='cowsay -f $cowfolder/kiss.cow'
alias kittysay='cowsay -f $cowfolder/kitty.cow'
alias koalasay='cowsay -f $cowfolder/koala.cow'
alias koshsay='cowsay -f $cowfolder/kosh.cow'
alias luke-koalasay='cowsay -f $cowfolder/luke-koala.cow'
alias mech-andsay='cowsay -f $cowfolder/mech-and.cow'
alias meowsay='cowsay -f $cowfolder/meow.cow'
alias milksay='cowsay -f $cowfolder/milk.cow'
alias moofasasay='cowsay -f $cowfolder/moofasa.cow'
alias moosesay='cowsay -f $cowfolder/moose.cow'
alias mutilatedsay='cowsay -f $cowfolder/mutilated.cow'
alias ponysay='cowsay -f $cowfolder/pony.cow'
alias pony-smallersay='cowsay -f $cowfolder/pony-smaller.cow'
alias rensay='cowsay -f $cowfolder/ren.cow'
alias sheepsay='cowsay -f $cowfolder/sheep.cow'
alias skeletonsay='cowsay -f $cowfolder/skeleton.cow'
alias snowmansay='cowsay -f $cowfolder/snowman.cow'
alias sodomized-sheepsay='cowsay -f $cowfolder/sodomized-sheep.cow'
alias stegosaurussay='cowsay -f $cowfolder/stegosaurus.cow'
alias stimpysay='cowsay -f $cowfolder/stimpy.cow'
alias susesay='cowsay -f $cowfolder/suse.cow'
alias three-eyessay='cowsay -f $cowfolder/three-eyes.cow'
alias turkeysay='cowsay -f $cowfolder/turkey.cow'
alias turtlesay='cowsay -f $cowfolder/turtle.cow'
alias tuxsay='cowsay -f $cowfolder/tux.cow'
alias uniponysay='cowsay -f $cowfolder/unipony.cow'
alias unipony-smallersay='cowsay -f $cowfolder/unipony-smaller.cow'
alias vadersay='cowsay -f $cowfolder/vader.cow'
alias vader-koalasay='cowsay -f $cowfolder/vader-koala.cow'
alias wwwsay='cowsay -f $cowfolder/www.cow'

alias aptthink='cowthink -f $cowfolder/apt.cow'
alias beavis.zenthink='cowthink -f $cowfolder/beavis.zen.cow'
alias bongthink='cowthink -f $cowfolder/bong.cow'
alias bud-frogsthink='cowthink -f $cowfolder/bud-frogs.cow'
alias bunnythink='cowthink -f $cowfolder/bunny.cow'
alias calvinthink='cowthink -f $cowfolder/calvin.cow'
alias cheesethink='cowthink -f $cowfolder/cheese.cow'
alias cockthink='cowthink -f $cowfolder/cock.cow'
alias cowerthink='cowthink -f $cowfolder/cower.cow'
alias daemonthink='cowthink -f $cowfolder/daemon.cow'
alias defaultthink='cowthink -f $cowfolder/default.cow'
alias dragon-andthink='cowthink -f $cowfolder/dragon-and.cow'
alias dragonthink='cowthink -f $cowfolder/dragon.cow'
alias duckthink='cowthink -f $cowfolder/duck.cow'
alias elephantthink='cowthink -f $cowfolder/elephant.cow'
alias elephant-in-snakethink='cowthink -f $cowfolder/elephant-in-snake.cow' alias eyesthink='cowthink -f $cowfolder/eyes.cow'
alias flaming-sheepthink='cowthink -f $cowfolder/flaming-sheep.cow'
alias ghostbustersthink='cowthink -f $cowfolder/ghostbusters.cow'
alias gnuthink='cowthink -f $cowfolder/gnu.cow'
alias head-inthink='cowthink -f $cowfolder/head-in.cow'
alias hellokittythink='cowthink -f $cowfolder/hellokitty.cow'
alias kissthink='cowthink -f $cowfolder/kiss.cow'
alias kittythink='cowthink -f $cowfolder/kitty.cow'
alias koalathink='cowthink -f $cowfolder/koala.cow'
alias koshthink='cowthink -f $cowfolder/kosh.cow'
alias luke-koalathink='cowthink -f $cowfolder/luke-koala.cow'
alias mech-andthink='cowthink -f $cowfolder/mech-and.cow'
alias meowthink='cowthink -f $cowfolder/meow.cow'
alias milkthink='cowthink -f $cowfolder/milk.cow'
alias moofasathink='cowthink -f $cowfolder/moofasa.cow'
alias moosethink='cowthink -f $cowfolder/moose.cow'
alias mutilatedthink='cowthink -f $cowfolder/mutilated.cow'
alias ponythink='cowthink -f $cowfolder/pony.cow'
alias pony-smallerthink='cowthink -f $cowfolder/pony-smaller.cow'
alias renthink='cowthink -f $cowfolder/ren.cow'
alias sheepthink='cowthink -f $cowfolder/sheep.cow'
alias skeletonthink='cowthink -f $cowfolder/skeleton.cow'
alias snowmanthink='cowthink -f $cowfolder/snowman.cow'
alias sodomized-sheepthink='cowthink -f $cowfolder/sodomized-sheep.cow'
alias stegosaurusthink='cowthink -f $cowfolder/stegosaurus.cow'
alias stimpythink='cowthink -f $cowfolder/stimpy.cow'
alias susethink='cowthink -f $cowfolder/suse.cow'
alias three-eyesthink='cowthink -f $cowfolder/three-eyes.cow'
alias turkeythink='cowthink -f $cowfolder/turkey.cow'
alias turtlethink='cowthink -f $cowfolder/turtle.cow'
alias tuxthink='cowthink -f $cowfolder/tux.cow'
alias uniponythink='cowthink -f $cowfolder/unipony.cow'
alias unipony-smallerthink='cowthink -f $cowfolder/unipony-smaller.cow'
alias vaderthink='cowthink -f $cowfolder/vader.cow'
alias vader-koalathink='cowthink -f $cowfolder/vader-koala.cow'
alias wwwthink='cowthink -f $cowfolder/www.cow'


# Open terminal and try them:
aptsay hello world.
ducksay hello.
elephantsay "i am round."
elephantthink "am i round!"
duckthink "Where are all the fish?"
tuxsay welcome
fortune | tuxsay
fortune | tuxthink
date | cowsay
whatis cowsay | cowthink
echo "i'm `whoami`" | tuxsay
bunnysay hello.


Time Counter

Time Counter

Time Counter

Create a time counter using Shell scripting.

# Create a file  time.txt  in home folder (any folder is ok). put '0' (zero) in it as second (starting value of time).

time.txt
0


# Create a  time.sh  script (in the same folder) and put this code in it.
#!/bin/sh
#file: time.sh
#description: keep track of time spend on computer.

file=time.txt

if [[ -f $file ]]; then
old_time=$( cat $file ) && new_time=$[ $old_time + 60 ] && echo $new_time > $file ;
else
echo '0' > $file ;
fi;
This script will take stored time value from  time.txt  and add 60 seconds to it when run.
So if the current stored time value is '0' (zero), it will add 60 seconds to it. and so on.


# Now we will run this script with crontab. Open Terminal and edit crontab:
crontab -e

..and add this line to the bottom of the file:
* * * * * /bin/bash ~/time.sh
This will make the  time.sh  to run and update  time.txt  simulteneously every minute.


# put this code in .bashrc file (found in home folder). with this we can check the time on terminal..
counter() {
second=$( cat ~/time.txt ) ;
day=$[ $second/86400 ] ;
hour_remain=$[ $second%86400 ] ;
hour=$[ $hour_remain/3600 ] ;
minute_remain=$[ $second%3600 ] ;
minute=$[ $minute_remain/60 ] ;

echo $day days $hour hours $minute minutes since 2014 April 12th.

}


# Open Terminal and enter counter:
0 days 0 hours 44 minutes since 2014 April 12th.


12 March 2014

Hidden power of Android

android

Hidden Power of android.

Every android phone comes with a Busybox , which provides several unix tools. (Android use a Linux kernel. ). unfortunately android does not provide a shell or command interpreter. like xterm in Debian/Ubuntu. user will have to install them manually. few of it are. • Below are some useful command found in android:

cal displays a calendar and the date of Easter
dd convert and copy a file
df , du report file system disk space usage
dos2unix , unix2dos convert file from one format to another.
ftpget , ftpput , tftp File transfer client & server.
httpd A barebone web server.
ifconfig configure a network interface
ip show / manipulate routing, devices, policy routing and tunnels.
md5sum , sha1sum , sha256sum , sha512sum compute and check MD5 , SHA1SUM , SHA256SUM , SHA512SUM message digest
nc The swiff army knife of network mapping.
netstat Display network connections, routing, tunnel etc.
ping , ping6 send ICMP ECHO_REQUEST to network hosts
ps Display process
sh , ash Shell or Command interpreter
sqlite3 A command line interface for SQLite version 3
telnet , telnetd A Telnet client & server.
traceroute , traceroute6 Trace the route to HOST
top Display top process
touch change file timestamps
udhcpc , udhcpd DHCP client & server.
uname Get system or kernel information
uptime Tell how long the system has been running.
vi Text Editor
wget The non-interactive network downloader.
who show who is logged on
whois client for the whois directory service


Other commonly use command:
awk , basename , id , hostname , clear , cat , date , diff , dirname , dmesg , echo , dnsdomainname , env , false , find , hostid , head , grep , less , ln , ls , mkdir , logname , more , mv , pwd , sleep , sort , rm , rmdir , sed , renice , reset , tail , tee , test , true , uniq , which , whoami , wc , yes .

Here are few example:

ping -c 5 google.com
sqlite3 foo.db
Web Server:
busybox httpd -h /mnt/sdcard/www/ -p 8888
Download Manager:
busybox wget -c www.example.com/map.png
Telnet Server:
busybox telnetd
busybox telnet 127.0.0.1
busybox whois www.google.com
busybox uname -a
busybox top -d 2
dd if=pic1.jpg of=pic2.jpg
busybox cal 2014
busybox netstat -tun


22 February 2014

Installing ADB in GNU/Linux

adb

Making ADB work in Linux (Debian/Ubuntu)

  1. Install Android Debug Bridge for GNU/Linux.

    • for Debian & DEB packages:
    sudo apt-get install android-tools-adb

    • for Redhat & RPM packages:
    sudo yum install android-tools-adb


  2. Connect android phone.
    lsusb
    Bus 001 Device 008: ID 058f:6366 Alcor Micro Corp. Android
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Find the corresponding line for your android phone.
    The Vendor & Product ID will be in XXXX:XXXX format. In our example the ID's is 058f:6366 .
    058f = VendorID.
    6366 = ProductID.


  3. Create Rules.
    sudo gedit /etc/udev/rules.d/51-android.rules
       you can use vi, nano, pico or any text editor in place of gedit.

    append the code to the file.
    SUBSYSTEM=="usb", ATTR{idVendor}=="058f", ATTR{idProduct}=="6366", MODE="0666", GROUP="plugdev"


  4. Create adb file in home ( ~ ) folder.
    mkdir ~/.android
    ( if not already created. )
    touch ~/.android/adb_usb.ini
    echo '0x6366' >> ~/.android/adb_usb.ini


  5. Restart udev.
    sudo service udev restart
    adb kill-server
    adb start-server


  6. Reconnect the Phone.
    You may need to disconnect and reconnect the phone again. and wait for a couple of minute to get it detected.
    adb devices
    List of devices attached
    19761202 device
    45024745 device




# The short way.

Copy this code into the terminal (replaces id's) and run it.

echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="6366", ATTR{idProduct}=="058f", MODE="0666", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/51-android.rules && mkdir ~/.android/ && touch ~/.android/adb_usb.ini && echo '0x6366' >> ~/.android/adb_usb.ini && sudo service udev restart && adb kill-server && adb start-server && adb devices
Replace the VendorID & ProductID with the one you got....



07 October 2013

Updating Linux Kernel

updating kernel

how to update ubuntu kernel to 3.10

The current long term linux kernel is 3.10 (correct as of 2013). so it's a good choice for previous longterm kernel user to jump to 3.10 for it bring many new features and improvement.
    Advantages of longterm kernel 3.10 are:

  • Tickless Timer
    Improve CPU performance and latency by reducing tick from 1000 to 1 per second.
  • Tail loss probe
    Improve network latency.
  • Bcache
    HDD performance improvement, by allowing SSD to act as cache.
  • ARM big.LITTLE support
  • MIPS KVM support
  • Memory, filesystem, Networking, crypto, Security, Virtualization Improvement
  • and many more...

Installing the latest kernel

# download the latest kernel in 'deb' format from kernel.ubuntu.com :

for 32-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_i386.deb

for 64-bit system
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014_3.10.14-031014.201310011335_all.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-headers-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.10.14-saucy/linux-image-3.10.14-031014-generic_3.10.14-031014.201310011335_amd64.deb

# install by running:
sudo dpkg -i *.deb

See The Changes

Unfortunately, you will have to reboot your computer to see the changes. the new kernel shall be visible in GRUB menu during bootup. Generally, GNU/Linux does never need to reboot for software, library etc et al to work after install. But kernel will be an exception.

# in rare case if it does not appear or update the grub menu itself:
sudo update-grub

note: this method will work on ubuntu and its derivatives.

23 September 2013

Making USB Modem work in GNU/Linux

the short way

Short tutorial for those who donot have all the time in the world to read a lengthy tutorial.
Open ' Terminal ' and run..
eject /dev/sr1
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Note the ID corresponding to USB/3G Modem.
sudo modprobe usbserial vendor=0x24e3 product=0x3e76


the long way

This tutorial will work for most 2G, 3G, 4G or any USB Modem under GNU/Linux using debian/ubuntu.

# Before inserting your usb modem. Open 'Terminal' and run the following command:
ls /dev/sr*
It'll output something like:
/dev/sr0
sr0 is mostly CD/DVD-Drive or any Serial Drive connected.

# Now insert your USB Modem and run the command again..
ls /dev/sr*
/dev/sr0 /dev/sr1
Note the extra serial device (sr1). it is your usb modem internal storage, because when attached they are dectcted as storage devices. It's explained in 'man usb_modeswitch'.
...When plugged in for the first time, they act like a flash storage and start installing the Windows driver from there. If the driver is already installed, it makes the storage device disappear and a new device, mainly composite with modem ports, shows up.

On Linux, in most cases the drivers are available as kernel modules, such as "usbserial" or "option". However, the device shows up as "usb-storage" by default...


# In 'Terminal':
lsusb
Bus 001 Device 004: ID 24e3:2205 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
note the ID corresponding your USB 3G Modem.

# Eject the modem storage:
eject /dev/sr1
..and..
lsusb
Bus 001 Device 004: ID 24e3:3e76 3G Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
It will show a new ID for the Modem.
24e3:3e76
24e3 is VendorID. 3e76 is ProductID of the modem.

# Make the modem visible to the system by running modprobe:
sudo modprobe usbserial vendor=0x24e3 product=0x3e76
Replace the ID with your Modem ID.

Wait a minute for the modem to appear in Network Manager.


12 March 2013

netstat usage example


Sometimes we need to know who are connected to our system. this can be to find malware or botnet that may be connecting us to somewhere. or some trojan stealling our data. end point is we need to find out network activities. this can be done with 'netstat'.


running netstat command will display all connection in a unix system.

netstat



to find out all TCP connection with netstat.

netstat -t



to find out all TCP and UDP connection...

netstat -tu



to find out all connection initiated by a program through TCP..

netstat -tp



to output all information in numeric format..

netstat -n



to find out all incoming connection and listening to..

netstat -l



you can also combine them..

netstat -tn



this will output TCP connection in Numeric format.

netstat -tupn


this will output all connection made by a software program in Numeric format.


these above are few example of netstat. you can check out man page for more.


put this script inside your bash profile in /home/user/.bashrc

#!/bin/bash

connection()
{
cat=$( netstat -tun | sed '1,2 d' | awk '{print $5}' | sed -r 's/(.*)\:(.*)/\1/g' | sort | uniq );

for i in $cat; do
netname=$( whois $i | grep -i netname | awk '{print $2}' );
echo "connection with: $netname ($i)";
done;
}


now open 'terminal' and type 'connection'.

this is just one stupid script. you can build better than this.
godspeed.


11 November 2012

automate home folder backup and software install script

unix user is notorous for oftenly changing Operating System (OS) or distro hopping. since new/increment version are realeased more frequently. it become significant / necessary to update to a newer release.

installing and configuring is time consuming if you have lots of software to install, say 30 or more. even more if you spend time playing solitaire or 0AD (no i had not played 0AD yet).

the saving grace in this situation is to create a script that will automate this work. first backup/copy your home folder (along with hidden folder).

below is the script (bash) to automate install of software after fresh install of new OS (Operating system).
the script for backing up setting from home folder is given below.



#add the name of software you want to install here seperated by [space].
cd $HOME
app_list="firefox gcolor2 gimp vlc";

for app in $app_list; do
if [[ `which $app` == "" ]]; then
echo "installing $app.....";
apt-get -y install $app; #install the app
else
echo "$app is already installed (skipping)."; #app is already
installed
fi;
done;


#script for backing up setting (from home folder).
cd $HOME ;
folder=backup ;
mkdir $folder ;
dir=$HOME/$folder/ ;

for i in `ls -A`; do
if [[ $i == .* ]]; then
if ( [[ $i == .thumbnails ]] || [[ $i == .cache ]]
|| [[ $i == .gvfs ]] || [[ $i == .local ]]
) ; #add more folder name that you don't want to backup then echo "Not copied $i";
else
echo "Copying $i";
cp -r $i $dir$i ;
fi;
fi;
done;

tar -cf backup.tar ./$folder ;
rm -r ./$folder ;




ps- sorry for my bad english. i'm still new in scripting. this is my first post.