Allowing multiple users to pull from a git repository on a shared server

A pretty common situation. Multiple developers working together on their local development machines and connecting to a central git repository with their own credentials. And there’s a dev/staging server where all users need to to have access to go login and pull the code. When you clone the git repository on the server, it essentially sets it up as the user who set it up and doesn’t allow other users to pull the code. Here’s how the config looks like:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = ssh://varun.verma@server.path.net/var/git/project_repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "dev"]
        remote = origin
        merge = refs/heads/dev
[branch "task/upgrading_django"]
        remote = origin
        merge = refs/heads/task/upgrading_django

And the user can pull the repository using git pull

Now, in order to configure the repository so that all users who have access to the server are able to pull the code, here’s how the configuration should look like:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = nouser@server.path.net/var/git/project_repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "dev"]
        remote = origin
        merge = refs/heads/dev
[branch "task/upgrading_django"]
        remote = origin
        merge = refs/heads/task/upgrading_django
[remote "varun.verma"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = varun.verma@server.path.net:/var/git/project_repo.git
[remote "other.user"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = other.user@server.path.net:/var/git/project_repo.git

And pull the repository by executing sudo git pull varun.verma task/upgrading_django. The system would ask for your local server password to sudo followed by the password for the remote git repository. This should resolve the problem.

Divide files into folders and zip them

I have a set of files that I usually have to divide into multiple folders and zip them together so I can upload on the cloud. It’s been a long time I’ve been manually doing this but then I thought I’d rather automate this altogether. So now all I have to do is calculate how many folders I need and a prefix for the folder, e.g. Color or BW and the program does the rest for me. It creates the folders, equally divides the files into those folders and zip them. Once the program finishes execution, I’m ready to upload them.

#/usr/bin/bash

# Enter number of folders to be created
# The program will create those folders and divide and move the files equally within those folders

# Exit if number of folders not provided
if [[ $1 -eq 0 ]]; then
	echo 'Enter number of folders to be created'
	exit 0
fi

# Exit if folder_previx is not provided
if [[ $2 = '' ]]; then
	echo 'Enter the prefix for the folder, e.g. Color or BW'
	exit 0
fi

# Get total number of files in directory
file_count=`ls -lrt *.jpg | wc -l`
echo Total files: $file_count

num_folders=$1
files_per_folder=$((file_count / num_folders))
files_per_folder=$((files_per_folder+1))
echo Files per folder: $files_per_folder

# Create folders; Divide and move images to folders and zip them so they are ready to upload
for ((i=1; i<=$num_folders; i++)); do
	if [[ $i -lt 10 ]]; then
		mkdir $2-Part0$i
		find . -name "*.jpg" -maxdepth 1 -type f | head -$files_per_folder | xargs -I{} mv {} $2-Part0$i
		zip -r $2-Part0$i.zip $2-Part0$i
	else
		mkdir $2-Part$i
		find . -name "*.jpg" -maxdepth 1 -type f | head -$files_per_folder | xargs -I{} mv {} $2-Part$i
		zip -r $2-Part$i.zip $2-Part$i
	fi
done

Executing psql from command prompt on Mac OSX after installing PostgreSQL

I installed PostgreSQL but wasn’t able to execute psql on the command prompt to execute queries. I had to add the PostgreSQL path to the PATH variable in order to do that. It’s best to append the path in the bash_profile so it’s ready and available every time the shell loads. Add the following lines (depending on the location of your PostgreSQL version)

# Modify PATH
export PATH=$PATH:/Library/PostgreSQL/9.5/bin

Mac – Update openssl

I had a hard time updating openssl on my Mac OSX. Here’s what I did to update the libraries:

Install and upate brew

brew update
brew install openssl
brew link --force openssl

openssl version

If one of the bad versions come up (1.0.1a-f), you can figure out which version of openssl you’re using, this way:

which openssl

Often this is from /usr/bin. To make sure you get the updated version, drop a symlink into /usr/local/bin to point to the updated openssl, like this:

ln -s /usr/local/Cellar/openssl/1.0.1g/bin/openssl /usr/local/bin/openssl

Note: You may have to exit and start the Terminal session to see the new changes.

As an alternative to that final step, some people replace the openssl in /usr/bin with a symlink to /usr/local/Cellar/openssl/1.0.1g/bin/openssl (or whatever your version is):

mv /usr/bin/openssl /usr/bin/openssl_OLD
ln -s /usr/local/Cellar/openssl/1.0.1g/bin/openssl /usr/bin/openssl

But this is known to cause problems with some more recent versions of OSX. Better to just insert a new symlink into /usr/local/bin, which should take precedence on your path over /usr/bin.

Original article: http://apple.stackexchange.com/questions/126830/how-to-upgrade-openssl-in-os-x

Configure Static IP on CentOS

## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.1.44
NETMASK=255.255.255.0


## Configure Default Gateway
#
# vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=centos6
GATEWAY=192.168.1.1


## Restart Network Interface
#

/etc/init.d/network restart

## Configure DNS Server
#
# vi /etc/resolv.conf

nameserver 8.8.8.8      # Replace with your nameserver ip
nameserver 192.168.1.1 # Replace with your nameserver ip

Debian – Change Hostname

Step 1: Edit /etc/hostname with the new name
Step 2: Edit /etc/hosts with the new name
Step 3: Reboot machine (shutdown -r now)

Find openssl and TLS protocol version

To get the version of OpenSSL installed on the OS:

$ openssl version
OpenSSL 1.0.1t  3 May 2016

To get the TLS/SSL protocol version, establish a secure connection to any of the servers on the web and the session information would have details of the Protocol.

$ openssl s_client -connect www.google.com:443
CONNECTED(00000003)
depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authority
verify return:1
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = www.google.com
verify return:1
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIEgDCCA2igAwIBAgIIK6L1O7WFg3UwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTYwOTE0MDgyMDQwWhcNMTYxMjA3MDgxOTAw
WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEXMBUGA1UEAwwOd3d3
Lmdvb2dsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCAmQKH
oFWTZ2HK2CN21xj8iEDvGoySc4qlPD3pmJpJFxO533WEPhnd//6QF+Krr3DMaLzS
8dj0mzSTHRnBgecv8/IYtvwaon28S8fdTJExgEZopfyCRTxG8FZc2v5t5VLW9Cd+
iuaQfAUTmAHcrq304XAjjaypJZ4ggnMzsJqaK2aRZUzVwzsADFjrMGjF9KGiu+Dy
obsuATblK9rgFixm2NQipPtt4kRuJbPp9qpJMcZael30mrunV8FLLIgLgEWYUzhO
+AOWeomKSHKsZO8akY7DFmSLpoY7A9BKHCByjbf9fwXuBFDrSPfpekYW2kT4NfHU
8mBpqyyrSCIzEhv3AgMBAAGjggFLMIIBRzAdBgNVHSUEFjAUBggrBgEFBQcDAQYI
KwYBBQUHAwIwGQYDVR0RBBIwEIIOd3d3Lmdvb2dsZS5jb20waAYIKwYBBQUHAQEE
XDBaMCsGCCsGAQUFBzAChh9odHRwOi8vcGtpLmdvb2dsZS5jb20vR0lBRzIuY3J0
MCsGCCsGAQUFBzABhh9odHRwOi8vY2xpZW50czEuZ29vZ2xlLmNvbS9vY3NwMB0G
A1UdDgQWBBSlyYl+/3NDrJ9jQw7V9viRhoXF2jAMBgNVHRMBAf8EAjAAMB8GA1Ud
IwQYMBaAFErdBhYbvPZotXb1gba7Yhq6WoEvMCEGA1UdIAQaMBgwDAYKKwYBBAHW
eQIFATAIBgZngQwBAgIwMAYDVR0fBCkwJzAloCOgIYYfaHR0cDovL3BraS5nb29n
bGUuY29tL0dJQUcyLmNybDANBgkqhkiG9w0BAQsFAAOCAQEAPSDolYdq1tkYsmeA
z1Pmb2MwA23nhcyUTP00QYLMYYG/8CxGhUc1tonuzA/ws0uy+3z+vF/4UxsGTlJL
yOMon68TU1OYGuGlQTLV7CUVb8K348dSz/Yv9zLGSX1CdD7OwurPKgSzyqfaLzgo
sn9YycO0SHlVRYf9hADKthZXjprnXScJ/uYWYqRn36Yd70zojdLqak0DUl51quVy
4s1VSauEEj76Prrq0L6HOw86CMIKWnLRTBGT7Y75g8ELD53H/j/rGJDrbFZOu3N0
aPcpIifFRyflDAY52c3DaLBlKnx6OBXaFoJwXa54ncQs4DXhJvzNDqf+X6BgTJ9x
jaMH7A==
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2
---
No client certificate CA names sent
---
SSL handshake has read 3727 bytes and written 415 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 519CA9ADE744B72A3E428105172579761A0E104E100CD11BA496497D4769E487
    Session-ID-ctx: 
    Master-Key: BEE6BD732D3D48B68FD96C37BD0A072B3A31C78253CDBA0F623D9DB0FCE5D06F9DC13AD298EE48922B85D824FCE35C74
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - fa 11 30 4d e2 45 8a a8-34 3b a5 b4 cd 1e c6 0a   ..0M.E..4;......
    0010 - ed 1e 03 d6 66 fb 83 c7-fb c5 ac e6 eb 69 2f c2   ....f........i/.
    0020 - 72 8f 38 a0 ba 1b 9b f5-34 70 63 6d 36 db 0a 0f   r.8.....4pcm6...
    0030 - 32 38 d9 03 df 10 78 2a-66 22 e5 eb c2 c4 c1 44   28....x*f".....D
    0040 - eb 36 ab d5 05 ed 54 20-37 8b b1 a8 2f 9a 2f ae   .6....T 7..././.
    0050 - 00 30 48 36 58 4c 80 1f-38 5c b9 da b3 85 8e f7   .0H6XL..8\......
    0060 - c8 dd 59 00 5c e8 ad 5e-7b 1d e7 1d e0 a2 ee 4b   ..Y.\..^{......K
    0070 - ec 5b d7 08 b0 24 1e a2-1a fd 47 74 b1 8b 1b b7   .[...$....Gt....
    0080 - 55 dd 01 c5 c7 29 fb f4-ec f3 88 27 d2 93 8c 32   U....).....'...2
    0090 - 7b e2 1b 54 b8 22 bf 90-f0 63 5c 46 14 9f a8 ad   {..T."...c\F....
    00a0 - 7b 5d 51 1d                                       {]Q.

    Start Time: 1473883627
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)