Sai Ram's Blog

thoughts, ramblings and ideas of a geek

Today I Learned | 23rd July 2013

[ Art of PI


Book Review: Version Control with Git, 2nd Edition

Version Control with Git 2/e by Jon Loeliger, Matthew McCullough from O’Reilly Media

The book was provided as part of the blogger’s review program.

This book covers topics from basics to advanced aspects of git varying from basic daily usage to once in a life time commands that you dream have existed.

Who is the book for ?

If you want to

  • know the modern day distributed version control systems
  • stop using p4, a disaster happens when you wait for few seconds to open a file on the server across the continent
  • learn about new data structures and concepts used in building an VCS
  • be amazed about no central authority managing files and easily download thousands of revision changes in a single shot
  • know how thousands of developers across the world contribute to thousands of projects without a central bottleneck
  • did not know that creating a new branch is a millisecond operation
  • stick with svn, but use the power of git

This book is for you if you fall under any of the options above

git on

The book starts off with the origins on how Git started and the big guns, one of the biggest distributed open source software, The Linux Kernel, uses it.

The initial chapters deal with Basic Git concepts which provide you explanations of keywords which are used later on.

Chapter (5) deals with adding, removing and moving operations which is the most used operation during active development.

Chapter (6) deals with commits, the heart of git version control and how its unique way it is what it is (the atomic changesets).

Chapter (7) provides a great in-depth explanation about branches and how you can create and experiment on branches w/o spoiling the existing tree and without even telling the server about the new changes. Here is where you will get to know that the creation of a branch is a millisecond operation rather than updating few table rows and locking them to avoid conflicts. Merging branches to keep or not keep history of the separate branch etc are explained in Chapter (9).

Looking back at what you or other authors have done is dealt in Chapter(8). Git can compare anything, commits, branches and tags (essentially any objects).

You slowly get into more advanced concepts of altering existing commits which I have personally dealt with in only one of my project for fixing my email address in a non-collaborated environment. Well modifying a commit has ‘disaster’ written all over it.

We get to see how git repositories are shared and what gets pushed when you initiate a push or pull. Git servers are explained as well to identify various forms you can send your code diff to the server so that it can be collaborated.

Did you know that you can share a directory on dropbox between collaborators and use it as a server as well ?

Patches are designed where you have a strict reviewer policy (like the Linux Kernel) to make a patch and send it across to be reviewed. Its added into the master once its added. This is also famously called ‘Pull Request’ on Github, where the team/community can discuss about the importance or requirement of the code change.

Hooks, the most underused by a developer but are more relevant to external services which use the code.

There are more interesting topics like

  • git filter-branch covered which you will not get to use unless hell broke lose in your repository
  • submodules - to reuse directories across multiple projects

Last, but not the least, an introduction to Github, which hosts hundreds of thousands open source repositories, is a nice addition though might look like its not necessary at first look. You can visually feel everything that you do on the command line on the UI. Many services like Continuous Integration for building & releasing software, verifying code quality, analysing code vulnerabilities etc were built on Github, essentially hook to the power of git helping developers complete the workflow.

Few of the stuff I personally learnt from the initial chapters

  • .git directory makes more sense now
  • I did not know about git bisect and had to manually iterate through commits
  • I got my hands dirty with git filter-branch. Warning: Use with extreme caution.

+++

+++

OReilly Product Page | Buy Book from Amazon


Today I Learned | 22nd July 2013

The Three Laws of Programming Language Design Source

  • What you get right, nobody mentions it.
  • What you get wrong, people bitch about.
  • What is difficult to understand you have to explain to people over and over again.


Hitting it off with Elixir

Book at Oreilly

Introducing Elixir

Review of Introducing Elixir

  • Well-written

  • Helpful examples

  • Easy to understand

  • Read through “Other Resources” from the ‘Preface’ before getting your hands on this book

  • This book is ideal for developers/students planning to start with the language.

  • Great introduction to the language syntax, programs in Elixir

  • Broad information about all types of basic data structures used and common patterns applied.

  • Covered pitfalls along with the examples

  • See Études for Elixir for exercises.

  • Also, The TOC is similar to Introducing Erlang


Configuring SSH Server

Basic README

# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

Default system level configuration

Change the default port from 22.

Port 2345

I don’t really know what this is

#AddressFamily any

There are can be associate this with either a single address or all the addresses the system has. This is important if your server is part of two networks so that you can use only one of the addresses to bind it to.

#ListenAddress 0.0.0.0
#ListenAddress ::

SSH Protocol to use

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

Host Key is something to uniquely identify a host.

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

Log files is the veins of the system. If things go bad, this is where you need to look. Describe what kind of logging should be done

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

Authentications

Self explanatory, paranoia in case you don’t want to hit your too often with password retries

# Authentication:
LoginGraceTime 2m
PermitRootLogin no
StrictModes yes
MaxAuthTries 6
MaxSessions 30

Public key authentication for safe and secure way. Generate an RSA token which will generate id_rsa (the private key and should not be shared) and id_rsa.pub(your public key, can be passed on to system where you want to login into).

#RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys
AuthorizedKeysCommand none
AuthorizedKeysCommandRunAs nobody

Don’t really know what this is

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

Keyboard based authentication of password from the client. If you feel too lazy to type a password all the time see public key authentication section # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no PasswordAuthentication no

Challenge Response Authentication

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

Kerberos is a network login system which is usually used in a medium to big organisations having network logins and multiple servers. If its 2-3 users and couple of servers that share passwords, its better off not setting Kerberos like systems.

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

You don’t want this in a normal server since the handshake itself eats up lot of time. Setting to no disables it

# GSSAPI options
GSSAPIAuthentication no
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

Environment variables

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

Other custom settings with which you can use the power of SSH and remote system

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no

If you want to open a Firefox from a different server. enable to ‘yes’

X11Forwarding no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes

Print message of the day

#PrintMotd yes

Enabled by default to let the user know when s/he was logged in last.

#PrintLastLog yes

This is helpful for not timing out the user

#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10

Tunnel is used for using the ssh server as a proxy

#PermitTunnel no

Chroot is a bigger concept which is to restrict environments / environment configuration with dependencies so that they do not interact with the rest of the system. Its like a Virtual Machine in your computer which does not know if its a Virtual Machine or a real server.

#ChrootDirectory none

Display information aka banner on what to do, what not, what the server has etc after logging in.

# no default banner path
#Banner none

Enable SFTP

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

If you want to allow a user to do something or not to do something, this is the place to put it

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server

Tips on ssh client configuration