Tuesday, April 19, 2016

Fedora 21 change device name to default

The 2 commands to be entered:

  1. net.ifnames=0
  2. biosdevname=0
Location to place the 2 commands and to complete the steps is as follows:
  1. Locate the file /etc/default/grub
  2. Look for the command: GRUB_CMDLINE_LINUX
  3. Append: net.ifnames=0 biosdevname=0 at the end of the GRUB_CMDLINE_LINUX within the double inverted commas
  4. Save the file
GRUB_CMDLINE_LINUX="... ... rhgb quiet net.ifnames=0 biosdevname=0"
  1. Terminal# grub2-mkconfig -o /boot/grub2/grub.cfg
  2. Terminal# reboot

Reference

Wednesday, April 13, 2016

Set Own URL for localhost apache

2 areas to look at...


  1. /etc/hosts
  2. /etc/httpd/conf/httpd.conf
  • For /etc/hosts
    • Add the IP address and the URL (ServerName) in this file
 Example: 127.0.0.1  www.mywebsite.com
  • For /etc/httpd/conf/httpd.conf
    • Add the following
 <VirtualHost *:80>
  ServerName www.mywebsite.com
  DocumentRoot "/var/www/'where the folder is'"
  DirectoryIndex index.html OR 'which ever file'
 </VirtualHost>


After everything done...
  1. Restart httpd.service
    • Terminal# systemctl restart httpd.service
  2. Restart web brower

Reference

Wednesday, April 6, 2016

Enable/Disable Touchpad

Finally! After some search and suffering all the wrong clicking and shit, found the way, and tested it worked for Enable/Disable touchpad on my laptop with Ubuntu 14.04 LTS.


  •  Find out what is the xinput <id> of the touchpad
    1. Terminal# xinput list

    1. Go to System Settings > Keyboard > Shortcuts > Custom Shortcuts
    2. Add 2 shortcuts naming
      1. Disable Touchpad
        • Name: "Disable Touchpad"
        • xinput set-prop 12 "Device Enabled" 0
      2. Enable Touchpad
        • Name: "Enable Touchpad"
        • xinput set-prop 12 "Device Enabled" 1
    3. Then select the key combination for activating the shortcut

Reference

Thursday, March 10, 2016

Auto start up script for Linux

DO NOT~! And I say DO NOT do an infinite loop for auto start up script before doing the necessary steps below~


  1. Backup the state of the machine before doing anything potentially stoopid
And that is the only step. If what is done, it is done stage, prepare a liveCD. Using the liveCD can get you in and resolve that issue.

Sunday, February 28, 2016

Permission Problem again...

Linux is good~ Always having permission problem. Always stopping me from making things work. Damn. Apache, which is the httpd service. Due to the fact that execution of bash script is done by thr "root" account, user Apache, have no permission to do it.

Fix the problem~

Problem is solved... 
By cheating... Damn... Using the command, "system('echo "ROOT PASSWORD" | sudo -u root -S COMMAND')"; will trigger the necessary access needed to run iwlist.


Reference

http://stackoverflow.com/questions/5652986/php-sudo-in-shell-exec

Monday, February 15, 2016

Functionality Consideration


  • The Webpage
    • Access Point (AP)
      • Changing AP SSID
      • Changing DHCP IP range
    • WIFI point
      • Display available wifi scan result
      • Enter WPA password to mouse click select WIFI

WIFI connected to AP

Dumb thing to do but it was done and it worked. Just to prove that the WIFI can connect to the AP.

Let's start and go to the process then~

  1. Run my "testscript2.sh" bash script with root
  2. Follow that, enable the second wireless dongle and follow the reference steps
    • Last step from the reference actually also verified if the wireless dongle is connected to the network

Reference

Thursday, February 11, 2016

AP and WIFI

Currently, the script for bringing up AP and WIFI is done and the NAT is done. The AP and WIFI is working fine, just that there is a need to do up a script for WIFI scanning. All in all is good.

There is also a shutdown script for AP and WIFI for the purpose of flushing the whole operation.

P.S. This is part of my progression journal. Sorry for those who is following the blog... =p

Wednesday, February 10, 2016

Bash Script Comment and in blocks

Here is some bash script troubleshooting technique that can be very useful when applied correctly.

Block comment for bash script in vi editor

  • In vi editor, comment from line n to m
    • <ESC>
    • :n,ms/^/#/
    • From line n to m substitute line start (^) with # sign
  • To remove comment
    • <ESC>
    • :n,ms/^#//
    • From line n to m substitute line start (^) followed by # with nothing //
Almost universal with /bin/bash for vi editor

There seems to be a problem... How are we to determine what line is what line... Count one by one? That's nuts~! But, there is a solution...

vi / vim editor does show line number
  • To display line numbers along the left side of the editor, type in the following command
    • <ESC>
    • :set number OR :set nu
  • To undo the line numbers
    • <ESC>
    • :set nu! OR :set number!
The above is just a one time thing. To make a permanent change for set number
  • Terminal# vi ~/.vimrc
  • In vi/vim editor
    • set number
    • Save and exit
      • Note: if you are curious on where is the file located, it may not be there. So just create the file and where will follow. Note of note: Only the user profile you create/edit the file will have the change.

Reference

http://www.cyberciti.biz/faq/vi-show-line-numbers/
http://stackoverflow.com/questions/947897/block-comments-in-a-shell-script

Saturday, February 6, 2016

Shorten Command line Bash Prompt

So to shorten the Bash Prompt just do the following changes:

  • Change for the current terminal instance only
    • Terminal# PS1='\u:\W\$ '
  • Change permanently
    1. Terminal# vi ~/.bashrc
    2.  Find the line
      • PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    3. Changes needed; of course you can copy a line in case you wanna change back
      • Remove '@h\' and replace '\w' with uppercase '\W'
    4. Save, exit and restart a new terminal

Reference

http://askubuntu.com/questions/145618/how-can-i-shorten-my-command-line-bash-prompt

Tuesday, February 2, 2016

Permission permission permission

It's always about permission, permission and permission.

The thing is the PERMISSION can be of GROUP/USER.

So let's see Users first.
  • root - the O'might one in linux
    • There is also a root group
  • Then there is wheel
    • There are a few places to look at
      • /etc/sudoers or visudo - same file
        • Enable wheel group
        • Search for "# %wheel ALL=(ALL)ALL", and remove hash to enable
      • /etc/passwd
        • Enable user/s in group directory for access and bash login
  • Verify user in which group
    • Terminal# su USERNAME -
    • Terminal# groups
  • There are also users like your administrators, users, APACHE and so on...
So now we come to Groups.
  • Group  : root
    • ## Allow root run any commands anywhere
    • "root ALL=(ALL) ALL"
      • So DO NOT anyhow tamper with anything you DO NOT know~!
  • Group : wheel
    • ## Allow people in group wheel to run all commands
    • "%wheel ALL=(ALL) ALL"
      • OR
    • ## Same thing without a password
    • "%wheel ALL=(ALL) NOPASSWD: ALL"
Linux Command : chown
  • To change user and/or group ownership of file/directory
    • chown owner-user "file"
    • chown owner-user:owner-group "file"
    • chown owner-user:owner-group "directory"
    • chown <options> owner-user:owner-group "file"
For /etc/hostapd and /etc/hostapd/hostapd.conf to be accessible by web server, (user: apache)
  1. Changing the owner-user and owner-group of /etc/hostapd/ (directory) and /etc/hostapd/hostapd.conf (file) to apache:wheel
    1. Terminal# chown apache:wheel /etc/hostapd/
    2. Terminal# chown apache:wheel /etc/hostapd/hostapd.conf
  2. This will enable the webpage to access and make changes to "hostapd.conf"
  • To verify if it works, enable bash login for user apache and adding apache into wheel group
    • Terminal# usermod -aG wheel apache
      • Verify by
        • Terminal# cat /etc/group | grep apache
        • Display : wheel:x:10:...,apache
    • Terminal# chsh -s /bin/bash apache
      • Verify by
        • Terminal# cat /etc/passwd | grep apache
          • OR
        • Just edit the "/etc/passwd"
        • Before => Display : apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
        • After => Display : apache:x:48:48:Apache:/usr/share/httpd:/bin/bash
    • Terminal# su apache
      • Then run any command that will write/read/execute the file in "/etc/hostapd"

Reference

Thursday, January 14, 2016

Web Server having permission denied

When accessing a webpage and having permission denied is a pain in the arse~!

So what do we do???

Well, the way to cheat is just to disable selinux

  • Terminal# vi /etc/selinux/config
    • SELINUX=disabled
  • Reboot and volla~ webpage access permitted~

Bash Script

Bash Script arguments are as follows:

  1. First Argument: $1
  2. Second Argument: $2
  3. Third Argument: $3

Example:

  • Terminal# ./script alpha bravo charlie
  • Variables: $1=='alpha'; $2=='bravo'; $3=='charlie'

Script Example

#!/bin/bash
echo "the $1 eats a $2 every time there is a $3"
echo "bye =)"

  • Terminal# ./script dog bone moose
  • Output: the dog eats a bone every time there is a moose
    bye =)



Reference

http://how-to.wikia.com/wiki/How_to_read_command_line_arguments_in_a_bash_script

Set and empty wpa_passphrase for hostapd.conf

The setting and empty wpa_passphrase is done. Now need to beautify it. Refer to NetCrypt Mobile Folder.

Linux sed replace

sed -i.bkp 5'i'"s/search/replace/" inputfile

  • -i.bkp take backup as inputfile.bkp and edit original file
  • 5'i' go to line 5
  • s/ search and replace
also can search specific word say 'NAME' and in same line search 'RAM' and replace with 'SHYAM'

sed -e '/NAME/s/RAM/SHYAM/g' filename



Reference

http://unix.stackexchange.com/questions/65064/how-to-find-and-replace-a-particular-string-in-a-specific-line

Linux: grep, sed

Find a line and append strings

  1. "grep" allows to find lines that contains the string/characters
  2. "sed" allows to append string/characters
$sed '/3696/ s/$/running file.txt'
foo1 3464
foo2 3696 running
foo3 4562
$sed 's/3696/& running/' file.txt
foo1 3464
foo2 3696 running
foo3 4562
P.S. Add the -i option to save the changes back to file.txt

Reference

http://stackoverflow.com/questions/14051883/how-to-append-text-to-a-specific-lines-in-a-file-using-shell-script

Fedora 21 Web Server for other connected devices

Although localhost, "127.0.0.1", can access on the local machine. Other connected devices will not be able to access to localhost web server.

The thing to lookout for is, FIREWALL~!


  1. Terminal# firewall-cmd --zone=public --add-port=80/tcp --permanent
    • Adding port 80 to public zone permanently~
  2. Terminal# firewall-cmd --reload
    • Reload the firewalld.service for rule to take effect
  3. Terminal# iptables-save|grep 80
    • Shows "-A IN_FedoraWorkstation_allow -p tcp -m tcp --dport 80 -m conntrack --ctstateNEW -j ACCEPT"
  4. Terminal# iptables -L|grep http
    • Shows "tcp -- anywhere tcp dpt:http ctstate NEW"

No GUI, kernel message flooding and installation of httpd

This input will be on:

  1. Remove GUI boot aka the graphical boot
  2. Remove excessive kernel messages from flooding the screen at login
  3. Installation of httpd essentials

For non-graphical boot

Terminal# systemctl set-default multi-user.target

OR

Terminal# systemctl set-default -f multi-user.target
// with --force

Double check the configured settings

Terminal# systemctl get-deafult

OR

Terminal# systemd.unit=multi-user.target

For stopping kernel message flooding

Terminal# sysctl -w kernel.printk="2 4 1 7"
//output
kernel.printk = 2 4 1 7
Terminal# sysctl kernel.printk
//output
kernel.printk = 2 4 1 7

Reference code:
                               CUR    DEF    MIN    BTDEF
0 - emergency
1 - alert
2 - critical
3 - error
4 - warning
5 - notice
6 - informational
7 - debug

For the installation of Apache 2 with PHP5 and MySQL support

//Installing MySQL/MariaDB5
Terminal# yum install mariadb mariadb-server

//Installing Apache 2
Terminal# yum install httpd

//Installing PHP5
Terminal# yum install php

//MySQL support in PHP5
Terminal# yum install php-mysqlnd php-mssql php-opcache

//Install phpMyAdmin

Fresh Installation of Fedora 21

Pissed off with the current situation with the Fedora 21 on my workstation; always showing this "rtl_usb ... request timeout", I have decided to delete the image and reinstall a fresh new setup.

This time round, I better journal down all the changes I am gonna make to keep track on the progress.


Sign off, R

Friday, January 8, 2016

Thursday, January 7, 2016

VirtualBox USB Devices not available

When host, Linux Distro, and GuestOS is also, Linux Distro, check for group.


  1. Terminal# vi /etc/group
    • Look for vboxusers
  2. Terminal# sudo usermod -G vboxusers -a $USER
    • $USER is the host
  3. Reboot host then open virtualbox to verify result

Reference:

http://askubuntu.com/questions/140081/virtualbox-doesnt-recognize-usb