Using Git with Remote Repository

Using Git with Remote Repository
By Shay Anderson on January 2014
The following article describes how to use git with a remote repository using Linux/Unix command line (Ubuntu 12.10 in this example).

Install and Configure Git
Start by installing git on your machine if not already installed: # apt-get update
# apt-get install gitTest git version: # git –version
git version 1.7.10.4If you haven’t done already, initialize your git config: # git config –global user.name “[your name]”
# git config –global user.email “[your email address]“You can view config settings using: # git config –list
Use Remote Git Repository
Initialize your local git directory using: # cd /var/www/sandbox/my-git-project
# git init
Initialized empty Git repository in /var/www/sandbox/my-git-project/.git/Next, add the remote repository, for this example I’m using a github.com repository: # git remote add origin https://github.com/shayanderson/test.gitPull the current remote git repository files: # git pull origin masterAdd all the files in your project to the local git repo: # git add .Commit to the local git repo: # git commit -m “Initial dump”And finally push the files to the remote git repository: # git push origin master

Turn on GREP Color Always

Turn on GREP Color Always
By Shay Anderson on January 2014
You can turn on grep color by using: # grep –color=always 123 file.txtOr, you can turn this option on always using: # export GREP_OPTIONS=’–color=always’This will allow grep color option always.

Install SSL Certificates in Apache HTTPD on CentOS 6.5 Server

Install SSL Certificates in Apache HTTPD on CentOS 6.5 Server
By Shay Anderson on February 2014
The following steps will assist in installing SSL certificates in Apache configuration on a CentOS Web server (CentOS 6.5 in this example).

Install Certificate Files
First, install your certificate files. I place them in these directories: /etc/httpd/conf/ssl.crt/example.com.crt
/etc/httpd/conf/ssl.key/example.com.key
/etc/httpd/conf/ssl.chain/example.com.chain.crt (ignore if not needed)
Change permissions of the certificate key file: # chmod 400 /etc/httpd/conf/ssl.key/example.com.key

Apache Configuration
Next, configure Apache for certificate files: # cp /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.BAK
# nano /etc/httpd/conf.d/ssl.confEdit the file to use your certificate, key and chain certificate (if needed): …
SSLCertificateFile /etc/httpd/conf/ssl.crt/example.com.crt

SSLCertificateKeyFile /etc/httpd/conf/ssl.key/example.com.key

SSLCertificateChainFile /etc/httpd/conf/ssl.chain/example.com.chain.crt

Ensure the Apache configuration file syntax is correct: # apachectl -t
Syntax OKRestart Apache gracefully: # service httpd graceful

credit:http://www.shayanderson.com/linux/install-ssl-certificates-in-apache-httpd-on-centos-6-5-server.htm

Deny External Access to Subversion Directories on Web Servers

Deny External Access to Subversion Directories on Web Servers
By Shay Anderson on February 2014
Denying access to Subversion directories on Web servers is a good idea.

Apache
Here is how to accomplish this in Apache (CentOS 6 example): # nano /etc/httpd/conf/httpd.confThen add these lines in the file and save:
Deny From All
Restart Apache: # service httpd restart
Nginx
Here is how to deny access in Nginx (CentOS 6 example): # nano /etc/nginx/conf.d/default.confAdd these lines in the server block and save file: # deny access to SVN dirs
location ~ /.svn/ {
deny all;
}
Restart nginx: # service nginx restart

Finally, test all access to Subversion directories for assurance.

Install Python 3 on CentOS 6.5 Server

Install Python 3 on CentOS 6.5 Server
By Shay Anderson on March 2014
In this article I will discuss installing Python 3 on a CentOS 6 server (CentOS 6.5 in this example).

Existing Python Packages
You may already have Python installed on your server, you can verify using: # which python
/usr/bin/python
# python –version
Python 2.6.6For this install we want to leave existing Python packages and executables in place.

Download Python 3
First, download the Python 3 package that you want to use, for this example I’m downloading version 3.3.2: # wget http://www.python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2 -O /var/tmp/Python-3.3.2.tar.bz2Unzip the archive: # bzip2 -cd /var/tmp/Python-3.3.2.tar.bz2 | tar xvf -

Install Python 3
Next, go to the extracted Python directory: # cd /var/tmp/Python-3.3.2Then setup compilation: # ./configure
Note: If you receive the error: configure: error: no acceptable C compiler found in $PATH during this step, run this command before configuring: # yum groupinstall “Development tools”Or Debian platforms: # apt-get install build-essential

Then build: # makeAnd install: # make install
Next, verify Python 3 installation: # /usr/local/bin/python3 –version
Python 3.3.2
Finally, create a link to Python 3 executable for easy usage: # ln -s /usr/local/bin/python3 /usr/bin/python3And check: # python3 –version
Python 3.3.2Now Python 3 is successfully installed and working.

Upgrade PHP 5.4 to PHP 5.5 on Ubuntu Server 12.10

Upgrade PHP 5.4 to PHP 5.5 on Ubuntu Server 12.10
By Shay Anderson on April 2014
Here are directions on how to upgrade from PHP 5.4 to PHP 5.5 on Ubuntu Server (12.10 in this example). Warning: the following instructions modify system settings and packages, make sure you know what you are doing before proceeding!

First, run update and install the package software-properties-common: # apt-get update && apt-get install software-properties-common
Next, add repo: # add-apt-repository ppa:ondrej/php5If you encounter an error and can’t add the repo try: # apt-get install python-software-properties
Finally, update the system and PHP 5.4 to PHP 5.5: # apt-get update && sudo apt-get dist-upgradeAfter finished restart Apache to make sure configuration file is working: # service apache2 restart

http://www.shayanderson.com/linux/install-google-authenticator-for-2-step-verification-on-centos-6-5.htm

How to Extend SSH Timeout on CentOS 6.5 Server

How to Extend SSH Timeout on CentOS 6.5 Server
By Shay Anderson on March 2014
This article explains how to extend the default timeout time for SSH on CentOS 6 servers (in this example CentOS 6.5).

First, edit the file /etc/ssh/sshd_config: # nano /etc/ssh/sshd_configUncomment these lines: #ClientAliveInterval 0
#ClientAliveCountMax 3And change values so they look like: ClientAliveInterval 120
ClientAliveCountMax 10
The 120 value for ClientAliveInterval means SSH will send KeepAlive packets in 120 second intervals. If SSH doesn’t receive a response back from the client the 10 value for ClientAliveCountMax means SSH will retry sending up to 10 times.

Finally, restart the SSH service: # service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]

http://www.shayanderson.com/linux/how-to-extend-ssh-timeout-on-centos-6-5-server.htm

How to Disable Root SSH Access on CentOS 6 Server

How to Disable Root SSH Access on CentOS 6 Server
By Shay Anderson on March 2014
The instructions below describe how to disable root SSH access for CentOS 6 servers. It is a good idea to disable root SSH access to prevent external root access.

Edit the file /etc/ssh/sshd_config: # nano /etc/ssh/sshd_configUncomment the line: #PermitRootLogin noSo it looks like: PermitRootLogin noSave the file and restart SSH: # service sshd restart

Disable SSH Login for User(s)

Disable SSH Login for User(s)
By Shay Anderson on April 2014
Disabling SSH logins for specific users can be a good idea for security. For example, you may want to disable a user like svn that is used only for internal server commands to control Subversion and the user will never need to login via SSH.

To disable SSH access for particular user edit the /etc/ssh/sshd_config file: # nano /etc/ssh/sshd_configThen add the following lines at the end of the file: # Deny users (space delimited)
DenyUsers user1If the DenyUsers entry already exists in the file use that entry. Close and save the file. Restart the SSH server: # service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]Now the user1 user cannot access the server via SSH access. To disable multiple users simply use a space delimiter, for example: DenyUsers user1 user2 user3You can also block all user’s SSH access and only allow specific users to login via SSH access using: AllowUsers user10 user11This would allow only user10 and user11 to access the server via SSH.

It is also possible to deny specific user groups using the DenyGroups entry, or to allow specific user groups using the AllowGroups entry.

How to Easily See Who’s Connected to Your MySQL Server

How to Easily See Who’s Connected to Your MySQL Server
I’m posting this here since it has been useful for me, and the blog is a nice place to keep public notes.
If you have servers which have multiple application servers connected to them, you often need to see things like who’s connected, how many connections they have, and which users. Using SHOW PROCESSLIST doesn’t work that well, since it gives you a row for each server.

What we want is an output similar to this:

+—————–+—————–+———-+
| host_short | users | count(*) |
+—————–+—————–+———-+
| slave1 | repl | 1 |
| slave2 | repl | 1 |
| localhost | event_scheduler | 1 |
| 111.111.222.111 | root, foo | 2 |
| 111.111.222.222 | appuser, bar | 3 |
| 111.111.222.333 | appuser, moshe | 9 |
+—————–+—————–+———-+

And it is achieved using a simple query such as this one:

SELECT SUBSTRING_INDEX(host, ‘:’, 1) AS host_short,
GROUP_CONCAT(DISTINCT USER) AS users,
COUNT(*)
FROM information_schema.processlist
GROUP BY host_short
ORDER BY COUNT(*),
host_short;

A final note: I’m not sure what version of MySQL this query needs to function, but it works great on MySQL 5.5, and should work just as well on MySQL 5.1.

Credit :http://blog.shlomoid.com/2011/08/how-to-easily-see-whos-connected-to.html