Bash script to mount SMB drive

I used to have my working directory on my home NAS with Samba file sharing. Below script helped me to avoid entering mount command and openvpn command every time I login into my computer.

cifs-utils must be installed on linux system to mount a SMB share using mount.cifs. cifs-utils can be installed using below command:

$ sudo apt-get install -y cifs-utils
#!/bin/bash

echo "Enter user for shared folder"
read shareuser
echo "Enter share password"
read sharepass

echo $shareuser
echo $sharepass

mount.cifs //<host>/<Name of SMB share> /root/Desktop/<Folder for mount> -o username=$shareuser,password=$sharepass
cd /root/Desktop/<Folder for mount>
openvpn OS*

I found this article “Install cifs-utils for SMB client” helpful if you want to mount Samba shares when system starts.

Useful commands to launch terminator

I like to use terminator over default terminal in linux, and I also like to use a bash script that can connect me to VPN and launch terminator with working directory as the directory that contains my project root.

I used OS* in below bash because name of vpn config file starts with “OS” and I have no other files in the directory with name starting with “OS”

#!/bin/bash
terminator --working-directory=<path to directory>
cd /media/root/USB && openvpn OS* &

 

Permission denied when executing C Program on Linux(from flash drive)

I had this issue when trying my first hello world like C program on Kali linux. I am able to save and compile C program using GCC (GNU compiler collection) but could not set the permissions to it.

The reason??? the file is on a USB drive. I am not sure if mounting it via VM ware is a reason. However, could not execute it from the pen drive.

Will be very happy if someone can explain the reason 🙂

I tried it, and you can notice that I am current on c-programming folder in my pend drive.

root@kali:/media/root/PWK/lab/c-programming# ls
firstprog firstprog.c
root@kali:/media/root/PWK/lab/c-programming#

The permissions before chmod:

root@kali:/media/root/PWK/lab/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:/media/root/PWK/lab/c-programming#

And after chmod:

root@kali:/media/root/PWK/lab/c-programming# chmod +x firstprog
root@kali:/media/root/PWK/lab/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:/media/root/PWK/lab/c-programming#

Now… moved the folder to Desktop and trying the same:

root@kali:~/Desktop/c-programming# ls
firstprog firstprog.c
root@kali:~/Desktop/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:~/Desktop/c-programming# chmod +x firstprog
root@kali:~/Desktop/c-programming# ls -l firstprog
-rwxr-xr-x 1 root root 7252 Jan 13 01:05 firstprog
root@kali:~/Desktop/c-programming#

And now executing the same:

root@kali:~/Desktop/c-programming# ./firstprog
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
root@kali:~/Desktop/c-programming#

Bingoooo!!! 🙂

Install sublime text on kali linux/debian

Install the GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

Ensure apt is set up to work with https sources:

sudo apt-get install apt-transport-https

Select the channel to use:

Stable:

echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Dev:

echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Update apt sources and install Sublime Text

sudo apt-get update 
sudo apt-get install sublime-text

Source: Sublime text

CD into directory with space character(s) in its name

CD command does not work if there is a space in the folder name.

Say we have a folder with name “folder with space in name” as below:

folder with space in name

And we try to CD into this folder as below… it just fails

root@kali:~/Desktop# ls
Links.txt PWK-DS folder with space in name mount-shared-folders.sh pwdump startup.sh
root@kali:~/Desktop# cd folder with space in name
bash: cd: too many arguments
root@kali:~/Desktop#

And the trick is to add quotes around it as below

root@kali:~/Desktop# cd "folder with space in name"
root@kali:~/Desktop/folder with space in name#

Tttrrrrrrrikkkkyyyy…. 🙂