Friday, May 30, 2014

Set up of Gitosis

Gitosis:

Gitosis is basically a set of scripts that help you manage the authorized_key file as well as implement some simple access controls.

Installing:

Gitosis requires some Python tools, so first you have to install the Python setuptools package, which Ubuntu provides as python-setuptools

sudo apt-get install python-setuptools

Next, you clone and install Gitosis from the project’s main site:

git clone git@path_of_project.git

cd gitosis
sudo python setup.py install

That installs a couple of executables that Gitosis will use. Next, Gitosis wants to put its repositories under /home/git , which is fine. But you have already set up your repositories in /opt/git , so instead of reconfiguring everything, you create a symlink:

ln -s /opt/git /home/git/repositories

Gitosis is going to manage your keys for you, so you need to remove the current file,
re-add the keys later, and let Gitosis control the authorised_keys file automatically. For now,
move the authorised_keys file out of the way:

mv /home/git/.ssh/authorized_keys /home/git/.ssh/ak.bk

You need to turn your shell back on for the “git” user, if you changed it to the git-shell command. People still won’t be able to log in, but Gitosis will control that for you. So, change
this line in your /etc/password file

git:x:1000:1000::/home/git:/usr/bin/git-shell

back to

git:x:1000:1000::/home/git:/bin/sh

Now initialised it with gitosis init where we want to initalised.

Now this is set up

Friday, May 23, 2014

Git Protocols

Git Protocols:

Git can use four major network protocols to transfer data: Local, Secure Shell (SSH), Git, and HTTP.

Local Protocols:

The most basic is the Local protocol, in which the remote repository is in another directory on disk. This is often used if everyone on your team has access to a shared filesystem such as an NFS mount, or in the less likely case that everyone logs in to the same computer. We can make clone by these commands.

commands:

git clone /path_of_file/project.git
 or
git clone file:///path_of_file/project.git

SSH Protocols:

Probably the most common transport protocol for Git is SSH. This is because SSH access to servers is already set up in most places—and if it isn’t, it’s easy to do. SSH is also the only network-based protocol that you can easily read from and write to.

commands:

git clone ssh://root@server:project.git
 or
git clone root@server:project.git

Git Protocols:

This is a special daemon that comes packaged with Git; it listens on a dedicated port (9418) that provides a service similar to the SSH protocol, but with absolutely no authentication. In order for a repository to be served over the Git protocol.

commands:

git clone git@path_of _project:project.git

HTTP/s Protocols:

The beauty of the HTTP or HTTPS protocol is the simplicity of setting it up. Basically, all you have to do is put the bare Git repository under your HTTP document root and set up a specific post-receive hook

commands:

git clone http://example.com/project.git

Friday, May 16, 2014

Deploy code in php

Deploy Code in php:

For deploy we will in need of install Capistrano which is a tool for deployment and also some of its essential package.

we can use aptitude or sudo apt-get for install .

aptitude install -y build-essential
aptitude install -y cvs subversion git-core libyaml-dev mercurial
curl -L get.rvm.io | bash -s stable  
source /etc/profile.d/rvm.sh
rvm reload
rvm install 2.1.0   
gem install capistrano --no-ri --no-rdoc
After this we have to create user at deployment server and have to add this in a group.

sudo addgroup www

# Create a new user:
# Usage: sudo adducer [user name]
sudo adduser deployer

# Follow on-screen instructions to user-related
# information such as the desired password.

# Add the user to an already existing group:
# Usage: sudo adducer [user name] [group name]
sudo adduser deployer www

Now give the permission to sudoers

# User privilege specification
root     ALL=(ALL:ALL) ALL
deployer ALL=(ALL:ALL) ALL


For permission we have to set this

# Set the ownership of the folder to members of `www` group
sudo chown -R :www  /var/www

# Set folder permissions recursively
sudo chmod -R g+rwX /var/www

# Ensure permissions will affect future sub-directories etc.
sudo chmod g+s      /var/www
Now on our server we have to set git and have to push data

# !! These commands are to be executed on
#    your development machine, from where you will
#    deploy to your server.
#    Instructions might vary slightly depending on
#    your choice of operating system.

# Initiate the repository
git init

# Add all the files to the repository
git add .

# Commit the changes
git commit -m "first commit"

# Add your Github repository link 
# Example: git remote add origin git@github.com:[user name]/[proj. name].git
git remote add origin git@github.com:user123/my_app.git

# Create an RSA/SSH key
# Follow the on-screen instructions
ssh-keygen -t rsa

# View the contents of the key and add it to your Github
# by copy-and-pasting from the current remote session by
# visiting: https://github.com/settings/ssh
# To learn more about the process,
# visit: https://help.github.com/articles/generating-ssh-keys
cat /root/.ssh/id_rsa.pub

# Set your Github information
# Username:
# Usage: git config --global user.name "[your username]"
# Email:
# Usage: git config --global user.email "[your email]"
git config --global user.name  "user123"    
git config --global user.email "user123@domain.tld"

# Push the project's source code to your Github account
git push -u origin master
Now initiate Capistrano and edit in deploy.rb and production.rb files

cap install

# mkdir -p config/deploy
# create config/deploy.rb
# create config/deploy/staging.rb
# create config/deploy/production.rb
# mkdir -p lib/capistrano/tasks
# Capified
nano config/deploy.rb
# !! When editing the file (or defining the configurations),
#    you can either comment them out or add the new lines.
#    Make sure to **not** to have some example settings
#    overriding the ones you are appending.

# Define the name of the application
set :application, 'my_app'

# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'https://github.com/user123/my_app.git'

# Define where to put your application code
set :deploy_to, "/var/www/my_app"

set :pty, true

set :format, :pretty

# Set your post-deployment settings.
# For example, you can restart your Nginx process
# similar to the below example.
# To learn more about how to work with Capistrano tasks
# check out the official Capistrano documentation at:
# http://capistranorb.com/

# namespace :deploy do
#   desc 'Restart application'
#   task :restart do
#     on roles(:app), in: :sequence, wait: 5 do
#       # Your restart mechanism here, for example:
#       sudo "service nginx restart"
#     end
#   end
# end
nano config/deploy/production.rb

 
# Define roles, user and IP address of deployment server
# role :name, %{[user]@[IP adde.]}
role :app, %w{deployer@162.243.74.190}

# Define server(s)
# Example:
# server '[your droplet's IP addr]', user: '[the deployer user]', roles: %w{[role names as defined above]}
# server '162.243.74.190', user: 'deployer', roles: %w{app}
server '162.243.74.190', user: 'deployer', roles: %w{app}

# SSH Options
# See the example commented out section in the file
# for more options.
set :ssh_options, {
    forward_agent: false,
    auth_methods: %w(password),
    password: 'user_deployers_password',
    user: 'deployer',
}   
and then send it to production

cap production deploy

Friday, May 9, 2014

Virtual box of ubuntu and its usage

VirtualBox:

Virtual box is a software which is used to run an operating system on your machine. It was created by innotek GmbH, purchased in 2008 by Sun Microsystems, and now developed by Oracle. It is installed on an existing host operating system as an application; this host application allows additional guest operating systems, each known as a Guest OS

Installation:

sudo apt-get update
sudo apt-get install virtualbox-4.3


After installation we can install any os in it. If we want to install ubuntu init then we have to download its image before it. After that we will select New option.

After setting its name and config we will select its image in "storage" tab.
 
After that we will install ubuntu in it. 
 
 

Friday, May 2, 2014

SSL (Secure Soket Layer)

Secure Socket Layer:

Secure Socket Layer is a protocol which is used to communicate over the Internet in a secure fashion.

SSL technology relies on the concept of public key cryptography to accomplish its tasks. In normal encryption, two communicating parties each share a password or key, and this is used to both encrypt and decrypt messages. While this is a very simple and efficient method, it doesn't solve the problem of giving the password to someone you have not yet met or trust.

SSL Works:

Step 1: XYZ creates a Certificate Signing Request (CSR) and during this process, a private key is generated.

Step 2: XYZ goes to a trusted, third party Certificate Authority, such as Trustwave . Trustwave takes the certificate signing request and validates XYZ in a two step process. Trustwave validates that XYZ has control of the domain xyz.com and that XYZ Inc. is an official organization listed in public government records.

Step 3: When the validation process is complete, Trustwave gives XYZ a new public key (certificate) encrypted with Trustwave's private key.

Step 4: XYZ installs the certificate on their webserver(s).

Customers Communicate with the Server using SSL:

Step 1: A customer makes a connection to xyz.com on an SSL port, typically 443. This connection is denoted with https instead of http.

Step 2: xyz.com sends back its public key to the customer. Once customer receives it, his/her browser decides if it is alright to proceed.

Step 3: If the customer decides to trust the certificate, then the customer will be sent to xyz.com his/her public key.

Step 4: xyz.com will next create a unique hash and encrypt it using both the customer's public key and xyz.com's private key, and send this back to the client.

Step 5: Customer's browser will decrypt the hash. This process shows that the xyz.com sent the hash and only the customer is able to read it.

Step 6: Customer and website can now securely exchange information.