Start and Stop ssh-agent

Below is the bash script used to start and stop ss-agent

#!/bin/bash

## in .bash_profile

SSHAGENT=`which ssh-agent`
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

## in .logout

if [ ${SSH_AGENT_PID+1} == 1 ]; then
    ssh-add -D
    ssh-agent -k > /dev/null 2>&1
    unset SSH_AGENT_PID
    unset SSH_AUTH_SOCK
fi

Rename Branch in github

Run below command change the branch name according to yours, Please pull before you run the below command


$ git branch -m old_branch new_branch 
$ git push origin :old_branch 
$ git push --set-upstream origin new_branch

Reverse Proxy for ssl (https)

Below is the VirtualHost conf example, Just change ServerName to yours And also change path of cert and key.
Check ssl module is enabled or not


<VirtualHost *:443>
    ServerName example.com

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile path/to/example.crt
    SSLCertificateKeyFile path/to/example.key
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / https://localhost:3026/
    ProxyPassReverse / https://localhost:3026/
</VirtualHost>

How to Install s3cmd in Linux and Manage Amazon s3 Buckets on ubuntu

On Ubuntu/Dabian:
$ sudo apt-get install s3cmd 
 
Configure s3cmd Environment
# s3cmd --configure
Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3
Access Key: xxxxxxxxxxxxxxxxxxxxxx
Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption
password: xxxxxxxxxx
Path to GPG program [/usr/bin/gpg]:
When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP and can't be used if you're behind a proxy Use HTTPS protocol [No]: Yes New settings:
Access Key: xxxxxxxxxxxxxxxxxxxxxx
Secret Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Encryption password: xxxxxxxxxx
 Path to GPG program: /usr/bin/gpg Use HTTPS protocol: True
HTTP Proxy server name: HTTP Proxy server port: 0
Test access with supplied credentials? [Y/n] Y
 Please wait, attempting to list all buckets... Success. Your access key and secret key worked fine :-) Now verifying that encryption works... Success. Encryption and decryption worked fine :-) Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'

 

Importing and Exporting MongoDB Databases

Exporting from MongoDB

To export the database, simply tell mongodump which database (or collection) you want to export, and where to export it to. Mine was the pets database, so my command looks like this:
mongodump -d pets -o petsbackup
This dumps the pets database into the petsbackup directory. Take a look at what we have in that directory now:
pets
├── animals.bson
└── system.indexes.bson

0 directories, 2 files
The only collection in my pets database is the animals collection, however you'll see a .bson file for each collection in your database, plus the system indexes collection. It is up to you whether you want to take individual collections, or a whole database, but bear in mind that your choice will dictate whether you get information about indexes etc when you import the data elsewhere.

Importing to MongoDB

To import, simply use the mongorestore command, which accepts either a single .bson file representing a collection, or a directory containing multiple files. Here's my example:
mongorestore -d pets /path/to/pets
You can specify any database name and path to files you like, so for taking backups or restoring additional copies of a database, this can be really handy. The mongo commands are well-documented and I found them easy to work with - hopefully this helps you work with them too!

Migrate git from one server to another


Give new origin name here i have given as testtest and http://new-repo.com is new server repository url change as per yours .

-----------------------------------------------------------------------------------------------------------------------------------------
git clone --bare  http://current-repo.com
-----------------------------------------------------------------------------------------------------------------------------------------
$git remote add testtest http://new-repo.com
-----------------------------------------------------------------------------------------------------------------------------------------
$git push -f --tags testtest refs/heads/*:refs/heads/*
-----------------------------------------------------------------------------------------------------------------------------------------

forever Upstart job for UBUNTU

Below is the upstart job for ubuntu for eg: create a file in /etc/init/test.conf and copy the below content to test.conf file, and change path to your app.js to yours, 



#!upstart
description "node.js server"
author      "kirthan shetty"

start on runlevel [2345] and started networking
stop on runlevel [!2345] or  stopped networking
expect fork

script
    export HOME="/root"

    echo $$ > /var/run/yourprogram.pid
    exec sudo -u root PORT=3004 /usr/bin/node /path to your app.js >> /var/log/yourprogram.sys.log 2>&1
end script

pre-start script
    # Date format same as (new Date()).toISOString() for consistency
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/yourprogram.sys.log
end script

pre-stop script
    rm /var/run/yourprogram.pid
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/yourprogram.sys.log
end script





to start #service test start
to stop # service test stop

Redirect url from non-www to www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.co [NC]
RewriteRule (.*) http://www.domain.co/$1 [L,R=301]

copy the above content to .htaccess file in your apache home directory 
Change the domain to u'r domain name

How to Find and Kill a Process that is Using a Particular Port

I had a problem with tomcat, it says that port 8080 is already in use so I can not use it …
What I did ?

1- Find what application/process is using the pro, type:

----------------------------------------------------------------------------------------------------
sudo netstat -lpn | grep :8080
----------------------------------------------------------------------------------------------------

You will get an output similar to this one
tcp6       0      0 :::8080                 :::*                    LISTEN      6782/java

2- I have got the process Id, which is 1234, now this is the process that is using port 8080.

3- Kill the process, type:
----------------------------------------------------------------------------------------------------------------------------------------
kill 6782
-------------------------------------------------------------------------------------------------

How to Upgrade OpenSSL on UBUNTU

How to Upgrade OpenSSL on Ubuntu

This quick tutorial outlines how to upgrade openssl to the latest version on Ubuntu Server 13.04.
A massive security hole has left over a third of the Internet's web servers vulnerable to the "Heartbleed Bug" which was announced to the public today. Use the following tool to check if your server is vulnerable:


You can run the following Bash script to upgrade your instance of OpenSSL to the latest version


--------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash

###
# Need to upgrade an Ubuntu 13.04 server to use OpenSSL 1.0.1g?
# Read and execute this script :D
###
# License: WTFPL, GPLv3, MIT, whatever; just patch your shit
# http://askubuntu.com/questions/444702/how-to-patch-cve-2014-0160-in-openssl
###

if [[ $EUID -ne 0 ]]; then
 echo "This script must be run as root" 1>&2
 exit 1
fi
wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz
wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz.asc

gpg --recv-key 0xD3577507FA40E9E2
# Dr Stephen Henson
# IMPORTANT! Manually verify that this is the correct key ID:
# http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xD3577507FA40E9E2
# https://www.openssl.org/about/

gpg --verify openssl-1.0.1g.tar.gz.asc openssl-1.0.1g.tar.gz

if [[ $? -eq 0 ]]; then
 tar xzvf openssl-1.0.1g.tar.gz
 cd openssl-1.0.1g && sudo ./config && sudo make && sudo make install
 # To link the old openssl library to a new version
 sudo ln -sf /usr/local/ssl/bin/openssl `which openssl`
 echo
 echo "DONE!"
fi

# eof
 
------------------------------------------------------------------------------------------------
  

 

Wifi driver instalation ( Ubuntu )

Please try:

sudo apt-get install  linux-backports-modules-cw-3.8-precise-generic

I believe cw-3.8 includes the modalias for your device.
If your device is still not shown, please post:
 
modinfo ath9k | grep 0036
dmesg | grep ath

Please get a working ethernet connection, open a terminal and do:
 
sudo apt-get install linux-headers-generic build-essential

Download this file to your desktop: https://www.kernel.org/pub/linux/kernel/projects/backports/2013/11/13/backports-20131113.tar.bz2 Right-click it and

select 'Extract Here.' Back to the terminal:
 
cd Desktop/backports-20131113/
make defconfig-ath9k
make
sudo make install

Reboot and let us know if it is working. You will have compiled the driver for your currently running kernel only. When Update Manager installs a newer kernel version, also known as linux-image, after you reboot, re-compile:
 
cd Desktop/backports-20131113/
make clean
make defconfig-ath9k
make
sudo make install
sudo modprobe ath9k

Start and Stop ssh-agent

Below is the bash script used to start and stop ss-agent #!/bin/bash ## in .bash_profile SSHAGENT=`which ssh-agent` SSHAGENTARGS="...