Nikhil Mungel

Carefully curated musings on programming, systems and learning.

SSH uses four TCP segments for each character you type

- -

Every time we press a key in an interactive SSH session, the SSH Client sends that keystroke as a TCP segment to the SSH Server. Here is a Wireshark capture of I having SSH-ed into my own machine and pressing a single key. I have not included packets indicating the setup and teardown of the TCP and SSH connections.

The Missing Man Page for ifconfig

- - posted in bash, ifconfig, linux, networking

This is actually very unlike a man page. It assumes that you know very little about TCP/IP networking. It also deals with only the parameter-less invocation of ifconfig, since other invocations are well documented in the real man page.
You can read the sections independently of one another, skipping what you already know. In this regard, it is quite like a man page.

Crafting Beautiful Command Line Applications with Ruby

- - posted in bash, cli, ruby

Earlier this year, Shishir Das and I presented at RubyConf India 2012 on how to go about crafting beautiful, utilitarian and functioning command line applications using Ruby.

And then this week, I got a chance to speak about the same topic at the Ruby Lightning Talk series organized by the great folks at ApartmentList and Thoughtbot┬áin the heart of SoMa in San Francisco. I condensed the full-format presentation from earlier this year into this crisp 10 minute talk that I’ve embedded here –

Restricted Bash

- - posted in bash, shell, ssh

While working on deploying a web-application recently, I needed to transfer a ‘build artifact’ (fancy name for a .tgz) from a Continuous Integration server to an RPM repository server.

We already have an existing RPM repository server that uses Apache, and once my tarball was in the correct location, it would be available over HTTP for all to consume.

Cutting to the chase – What is the simplest way by which I could automatically transfer a ~20 MiB file from one CentOS host to another? I didn’t want to install an FTP server or any extra Apache module on the existing RPM host that would then support multi-part file uploads.

The quickest solution, it seemed was an scp or an rsync.

So, how would this CI host be authorized to open an SSH tunnel to the web-server? Where would the identity key reside? There is no elaborate keyserver in this ecosystem.

I decided to the transfer the responsibility of protecting the system from the identity key to the remote host’s operating system.

A new user called tarballs on the RPM repository host with its HOME set to /var/www/html/tarballs, and set its SHELL to rbash.

Bundler and RVM

- - posted in bash, bundler, rails, ruby, rvm

Almost everyone I know who writes any Ruby outside of the irb REPL uses Bundler. And everyone I know uses RVM to manage their rubies and their gems locally, except for this one guy who uses rbenv (which is a great tool, more on that in another blog post).

I have observed people use different strategies and workflows with bundler and RVM, since there is at least one overlap in what they do: manage collections of rubygems. Bundler calles them bundles and RVM calles them gemsets.

Broadly, here are two patterns.

XON and XOFF

- - posted in bash, emacs, signals, ssh, vi, vim

It started with SSH sessions to the Bangalore data center freezeing up sporadically.

It wasn’t all that sporadic, a pattern was noticed soon enough – a harmless C-x C-s issued when inside vi.

Unfortunately, most distros do not come bundled with emacs and I have to resort to botching up and fumbling with vi (or vim) to edit a few configurations now and then. Everytime I’d tweak an LXC configuration with vim and hit C-x C-s on the unsuspecting editor, things would freeze up. It’d refuse to respond to even the widely respected un-interceptability of the ^Z. Since I use a multiplexed SSH control-master, I’d waste no time opening another SSH to the obstinate host in a different tab and mind my business.

DevOps at ChicagoRuby

- - posted in devops, rails, ruby

Presented earlier this year in January 2011, Chris Breisemeister put forth a few practices that we follow when working with a variety of large enterprise clients on software delivery and enablement.

We start right from the basics of what lifecycle does a line of code typically follow to how different environments should be configured and managed.

Since we talked to a Ruby audience, we talk specifically about release practices and workflows of Ruby on Rails applications centered around Continuous Integration that have enabled us to deploy extremely fast.

Chris Breeze is a colleague who works out of the Chicago office, he is also the man behind Chicago Carp.

Deployment Patterns in the Ruby on Rails World

- - posted in devops, rails, ruby

@AjeyGore and I presented deployment patterns and paradigms that we’ve observed and influenced while consulting and enabling numerous clients.

The ones at the beginning are ideal for smaller scale applications that do not typically need to scale fast. We also go on to talk on more advanced patterns by using system-level packing tools that can enable an application to scale very rapidly if you use Chef or Puppet.

We presented this at DevOpsDays Bangalore 2011.

Time Saving Bash Tricks

- - posted in bash, cli, ssh

This is a followup from the lightning talk 5 Time Saving Bash Tricks that I gave at DevOpsDays, Bangalore 2011.

SSH multiplexing

Adding these to ~/.ssh/config or /etc/ssh_config will allow you to multiplex one SSH connection to open multiple terminals, multiple scp and git push without having to authenticate over keys or passwords.