Reference first argument in move command

mv /path/to/dir/filename.txt !#^:h/newname.txt

Where :

! means history expansion

# means command currently being typed

^ means the first argument

:h gets the “head” that is the directory without the filename portion

Apache rewrite rules

Rewrite to a folder and hide the folder name in url :

RewriteCond     %{SERVER_NAME}    ^sitename.com        [NC,OR]
RewriteCond    %{SERVER_NAME}    www.sitename.com    [NC]
RewriteCond    %{REQUEST_URI}    !^anyfiletoexclude.php    [NC]
RewriteCond    %{REQUEST_URI}    !^/foldertoredirect/    [NC]
RewriteCond    (.*)        /foldertoredirect/$1

force use www

RewriteCond    %{SERVER_NAME}    ^website.com$
RewriteRule    ^/(.*)        http://www.website.com/$    [L,R]

Configure Vsftpd in amazon ec2 instance

pasv_enable=YES
 pasv_min_port=12000
 pasv_max_port=12100
 port_enable=YES
 pasv_address=<public ip of your elastics>

Reset A2Billing admin password

echo "update cc_ui_authen set pwd_encoded = '410fc6268dd3332226de95e42d9efa4046c5463769d7493b85e65cfa5c26362dc2455cc23c0bc5831deb008def4ab11a9eaa9b76ba3f377da134f39ec60dd758' where login='root'" | mysql -pPASSWORD DATABASE

 

This will reset username and password to : root/changepassword

Mounting Open stack Cloud Object Storage in Linux

Prerequisites:

libcurl and libcurl-devel  fuse, fuse-devel, and fuse-libs libxml2 and libxml2-devel

Download the cloudfuse :

This version doesnot support mounting at container level :

wget https://github.com/redbo/cloudfuse/tarball/master

This supports mounting at container level:

https://github.com/vfloz/cloudfuse/tarball/master

tar -zxvf master

cd <extracted dir>

./configure

make && make install

 

Create an entry in your fstab:

cloudfuse  /mount/point fuse username=<username>,api_key=<api key>,container=containerName,authurl=<authurl>

mount -a

Read readme.txt for more information.

Perl Issues and Solutions

Display The Include paths for perl :

perl -e 'print join("\n", @INC);'

View Cpan Configuration:

cpan>o conf

Find perl module’s Path:

perl -MList::Util -e'print $_ . " => " . $INC{$_} . "\n" for keys %INC'

 

Delete Rules in Iptables

iptables -D (Chain Name) ( RuleNum)

eg.

iptables -D FORWARD 1

You can delete all rules from filter chain by typing :

iptables -F

or from nat table

iptables -F -t nat

Creating SSL Certificates

Create a Self Signed Certificate :

1. Generate A Server Key : #openssl genrsa -des3 -out server.key 4096

2. Generate the Signing Request using the key above #openssl req -new -key server.key -out server.csr

3.Sign the certificate signing request. #openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

4. Now create a version of key that doesn't need a password : openssl rsa -in server.key -out server.key.insecure mv server.key server.key.secure mv server.key.insecure server.key

Generating Your Own Certificate Authority :

In order to create your own CA and sign a server certificate with it. Note: Common name of the CA and the Server Certificates must not match.

Steps :

1. Use IP address if you dont have the FQDN.

openssl genrsa -des3 -out ca.key 4096 openssl req -new -x509 -days 365 -key ca.key -out ca.crt

2.Generate a Server key and request for signing :

openssl genrsa -des3 -out server.key 4096 openssl req -new -key server.key -out server.csr

3.Sign the Certificate signing request with the Self created Authority

openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt

Optional : You can check the keys and certificates :

openssl rsa -noout -text -in server.key openssl req -noout -text -in server.csr

openssl rsa -noout -text -in ca.key openssl x509 -noout -text -in ca.crt

4. Remove password from server.key so that apache doesnot need password :

openssl rsa -in server.key -out server.key.insecure

mv server.key server.key.secure

mv server.key.insecure server.key

Finally : Copy the files and adjust apache..

  • copy the .crt and .key file to /etc/httpd/conf/
  • Turn on the SSL engine and reference the server.crt and server.key
  • Edit ssl.conf

                      SSLEngine on

                      SSLCertificateFile /etc/httpd/ssl.crt/server.crt

                     SSLCertificateKeyFile /etc/httpd/ssl.key/server.key

configure apache to listen to https :

                     Listen x.x.x.x:443

                     LoadModule ssl_module modules/mod_ssl.so

configure SSL

                    Virtual Host : DocumentRoot "/var/www-ssl/html"

                   ServerName xxx.xxx.xxx.xxx:443

Now Restart Apache and you have ssl working on your site.

Installing Vnc Server on Linux Machine without monitor

Vnc Installation Without Monitor

Packages Required :

1.vnc

2.vnc-server

3.Desktop Environment KDE or GNOME

Configuring VNC :

1. Add users like normal users.

2. login to each users

3. create password by running vncpasswd

4. It creates .vnc folder

5. Edit /etc/sysconfig/vncservers, and add the following to end of the file

VNCSERVERS="1:amitn 2:someuser"

VNCSRVERARGS[1]="-geometry 640×480"  ( for amitn )

VNCSRVERARGS[2]="-geometry 640×480"  ( for someuser)

VNCSRVERARGS[1]="-geometry 800×600"

6.Create Xstartup scripts by starting and stopping vncserver as root

/sbin/service vncserver start

/sbin/service vncserver stop

7. Login to each user and edit xstartup script

8. vi .vnc/xstartup

#!/bin/sh

# Add the following line to ensure you always have an xterm available.

( while true ; do xterm ; done ) &

# Uncomment the following two lines for normal desktop:

unset SESSION_MANAGER

exec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] &&

exec /etc/vnc/xstartup [ -r $HOME/.Xresources ]

&& xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & xterm -geometry 80×24+10+10 -ls -title "$VNCDESKTOP Desktop" & startkde &

Using Rsync to Syncronise files between servers

Rsync is a nice utility to synchronize files and folders between two servers securely and efficiently. It only copies the difference so making the process much faster and efficient.

Ok, here i will show you how to setup rsync.

1. Download the rsync package. Click Here

2. Untar the package and enter into the directory.

3. ./configure

4. make

5. Make install

6. Create the configuration file for rsync

#vi /etc/rsyncd.conf

#/etc/rsyncd.conf
secrets file = /etc/rsyncd.secrets
motd file = /etc/rsyncd.motd #Below are actually defaults, but to be on the safe side...
read only = yes
list = yes
uid = nobody
gid = nobody

[out]
comment = comment for your directory
path = /home/rsync/out

[confidential]
comment = For your eyes only
path = /home/rsync/secret-out
auth users = amit,nishant
hosts allow = 192.168.100.100
hosts deny = *
list = false

#save the file.

Now create a script for starting and stopping the daemon :

#vi /etc/init.d/rsyncd

#!/bin/sh
# Rsyncd This shell script takes care of starting and stopping the rsync daemon
# description: Rsync is an awesome replication tool.

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/bin/rsync ] || exit 0

case "$1" in
start)
action "Starting rsyncd: " /usr/bin/rsync --daemon
;;
stop)
action "Stopping rsyncd: " killall rsync
;;
*)
echo "Usage: rsyncd {start|stop}"
exit 1
esac
exit 0

# Now create a symbolic link at /etc/rc.d/rc3.d

#cd /etc/rc.d/rc3.d

#ln -s /etc/init.d/rsyncd rsyncd

Now start rsyncd at the server side

#service rsyncd start

You can issue this command to copy the files :

rsync -avz amit@server name or ip::out /home/rsync/in

or you can use the following command to use ssh

rsync -avz -e ssh rsync@server_ip:/home/rsync/out/ /home/rsync/from_remote

Now you can set this up in a cron.