Tuesday, January 13, 2015

Encrypt Decrypt file(s) using Openssl

Wonder how to encrypt file(s) using openssl with a password?
Check my video :)


For password I have used des3 encryption in openssl.

Sunday, January 11, 2015

Secure SSH Login to Your Ubuntu VPS

Change SSH Port to something else.

Using something other than the default Port 22 for the ssh server can help avoid attacks by script kiddies. To do so, run command to edit the ssh config file:


mahesh@mknsoft.com ~
[09:41:40]⌘  vim /etc/ssh/sshd_config


Find out Port 22, change to Port 22222 or any other number between 1024 and 65536. After this step, you can do SSH access by running below command:


mahesh@mknsoft.com ~
[09:42:40]⌘  ssh 192.168.1.100 -l root -p 22222


Tuesday, December 30, 2014

Setting up Push-to-Deploy with git

Requirements:

  • I have a computer at home/office.
  • We have a VPS on web.
  • On VPS we have a location for our website i.e. /var/www/example.com
  • I need a version control system.
  • I don't want to develop and upload changes manually.
  • I want to push a specific branch i.e. www to vps for deployment.
How can I achieve my goal? Find below the answer:

1. Lets create an example directory first.


Lets create a temp directory and then create sub-directories under it.


mahesh@mknsoft.com ~
[06:43:00]⌘  mkdir test && cd test

mahesh@mknsoft.com ~/test
[06:43:14]⌘  mkdir vps dev www


dev = My development computer
vps = Virtual Private Server on Internet
www = i,e, /var/www/example.com/

2. Setup a --bare git repo in vps.



mahesh@mknsoft.com ~/test
[06:43:33]⌘  cd vps

mahesh@mknsoft.com ~/test/vps
[06:45:51]⌘  git init --bare
Initialized empty Git repository in /Users/mahesh/test/vps/


3. Setup git repo in dev, add remote and do initial commit.



mahesh@mknsoft.com (BARE:master) ~/test/vps
[06:45:59]⌘  cd ../dev

mahesh@mknsoft.com ~/test/dev
[06:49:16]⌘  git init
Initialized empty Git repository in /Users/mahesh/test/dev/.git/

mahesh@mknsoft.com (master #) ~/test/dev
[06:49:31]⌘  git remote add origin ../vps

mahesh@mknsoft.com (master #) ~/test/dev
[06:50:15]⌘  echo "Test line 1" >> file.txt

mahesh@mknsoft.com (master #) ~/test/dev
[06:50:40]⌘  git add .

mahesh@mknsoft.com (master #) ~/test/dev
[06:50:50]⌘  git commit -m "Initial commit."
[master (root-commit) 1683234] Initial commit.
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt

mahesh@mknsoft.com (master) ~/test/dev
[06:51:07]⌘  git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 231 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ../vps
 * [new branch]      master -> master


4. How to publish?


At this point we are still unable to publish anything inside www directory. Now what can I do? Humm..., this is where hooks come to picture. Lets create a hook (post-receive) inside vps to track new pushes.


mahesh@mknsoft.com (master) ~/test/dev
[06:51:21]⌘  cd ../vps/hooks

mahesh@mknsoft.com (BARE:master) ~/test/vps/hooks
[07:02:04]⌘  touch post-receive

mahesh@mknsoft.com (BARE:master) ~/test/vps/hooks
[07:02:28]⌘  chmod +x post-receive


Lets get inside post-receive and write some code as per requirement.


mahesh@mknsoft.com (BARE:master) ~/test/vps/hooks
[07:02:49]⌘  vim post-receive




  1 #!/bin/bash
  2 
  3 read oldrev newrev refname
  4 echo "Old revision  : $oldrev"
  5 echo "New revision  : $newrev"
  6 echo "Reference name: $refname"
  7 
  8 BRANCH=${refname#refs/heads/}
  9 
 10 echo "Pushed branch : $BRANCH"
 11 
 12 if [ $BRANCH = www ]; then
 13         export GIT_WORK_TREE=/Users/mahesh/test/www
 14         git checkout -f www
 15         echo "Published."
 16 else
 17         echo "Push on branch www to publish"
 18 fi


So fare so good. Lets test it out right away.


mahesh@mknsoft.com (BARE:master) ~/test/vps/hooks
[07:10:50]⌘  cd ../../dev

mahesh@mknsoft.com (master) ~/test/dev
[07:14:13]⌘  git branch www && git checkout www
Switched to branch 'www'

mahesh@mknsoft.com (www) ~/test/dev
[07:14:44]⌘  git push origin www
Total 0 (delta 0), reused 0 (delta 0)
remote: Old revision  : 0000000000000000000000000000000000000000
remote: New revision  : 168323487f78ac6e03022ed4b456e1c0e95af21b
remote: Reference name: refs/heads/www
remote: Pushed branch : www
remote: Switched to branch 'www'
remote: Published.
To ../vps
 * [new branch]      www -> www

mahesh@mknsoft.com (www) ~/test/dev
[07:15:28]⌘  ls ../www
file.txt

Note: If you push in master branch, new updates will not be published as condition specified in post-receive source code.

Thursday, December 25, 2014

Bash script - utility bin

Bash utility script files for all.
Can be useful for linux based OS users. Below is the location.

https://github.com/t2mahesh/bin

Fork, contribute or comment is welcome. Enjoy :)

Wednesday, October 8, 2014

Start a Simple Web Server from Any Director

If you haven't installed Python yet, do it right away. This thing requires Python and it's available as a module inside Python.

Navigate to the directory using your terminal window where you want the web server to start and issue the following command:

$ python -m SimpleHTTPServer 8080

It will start the web server right away.

Open web browser and goto:
http://localhost:8080

Enjoy :)


Friday, September 27, 2013

Screen Lock app for Android


Screen Lock app for Android by Prahallad is very handy for quickly locking off the device. Just a click to turn off the screen and lock the device. Animations are their so you can turn off with style. There
are various options to use the app quite smoothly. And the important thing is; it has no bugs at all, and found to be working perfectly in almost all the devices. Most such apps fail to work right on Android 4.0 and above but this Screen Lock app works just perfect and act as unbeaten from its 100s of competitors.




You get lots of options to use Screen Lock app as you need:
  1. Create a shortcut
  2. Use widget
  3. Enable in notification area
  4. Shake to lock the device
  5. Screen on and off without locking the device (Available in Pro version). Very useful one.
Features include with lock:
  1. Enable vibration upon lock
  2. Adjust vibration strength
  3. Enable lock and unlock sound
  4. Select sounds already present in your device
The development team has promised to give more features with the upcoming future releases. Some of the interesting features to be expected are:
  1. Custom name for the shortcut
  2. Various icons to choose
  3. Awesome device movement to Lock and to wakeup the device. (Will be very interesting to use)
The very interesting part is the flexibility provided with Transition Animation Scale. Unlike other such apps, this app adjusts itself with the value as set in your device, making the animation smoother and make it a perfect app. Also no screen flickering after lock is really awesome. Not to mention the icon provided with free and with pro version of this app is just outstanding.



Sunday, July 21, 2013

lsb_release error, Ubuntu 12.04

It's a crash because of TeamViewer installation, it has been reported to TeamViewer developer team. Meanwhile a solution is proposed by gerlosgm which works perfectly fine for me.


Thanks for the solution :)