Skip to content

Instantly share code, notes, and snippets.

@sankage
sankage / two_factor_ssh.md
Created September 23, 2011 14:29
Two Factor Authentication for ssh

Simple Two-Factor SSH Authentication

Posted on September 23 2011 by Richard Taylor (@moomerman)

In a two-part post I'm going to show you some tricks you can do with SSH logins. This post covers setting up two-factor SSH authentication with the Google Authenticator app.

I was recently getting some servers in shape so I can pass the Payment Card Industry standards questionnaire and one requirement was two-factor authentication access to the server. I queried whether SSH key + passphrase was acceptable but didn't get a clear answer so I figured I'd explore setting up another authentication factor myself, plus it piqued my interest.

After a bit of research I found it was possible using a PAM module but it doesn't work along with SSH key authentication (only password authentication) and I only use SSH key logins for my servers.

The magic

@sankage
sankage / Respondent.rb
Created November 29, 2011 01:07
Collection Problem
# Respondent model
class Respondent < ActiveRecord::Base
belongs_to :office
has_many :comments
has_many :answers
end
@sankage
sankage / answer.rb
Created November 29, 2011 02:26
Collection Sub-Selection
# Answer model
class Answer < ActiveRecord::Base
belongs_to :respondent
belongs_to :question
end
@sankage
sankage / Answer.rb
Created December 15, 2011 16:50
Question & Answers associations
class Answer < ActiveRecord::Base
belongs_to :respondent
belongs_to :question
end
@sankage
sankage / function.coffee
Created April 3, 2012 18:07
CoffeeScript: self executing anonymous functions
# Is there a coffeescript way of doing this?
(function($, exports){
# doing random stuff here
})(jQuery, window);
# Other than this:
( ($, exports) ->
# doing random stuff here
@sankage
sankage / prime.coffee
Created June 23, 2012 21:39
Prime Numbers
class Prime
constructor: (@prime = 2) ->
@history = [@prime]
isPrime: (num) ->
result = true
if num isnt 2
if num % 2 is 0
result = false
else
@sankage
sankage / CodeTV::highlight_watched
Created November 26, 2012 02:04
CodeTV - Mark watched videos bookmarklet
javascript:(function(){var div,filler,link,names,video,videos,_i,_j,_len,_ref,__slice=[].slice,__indexOf=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};if(localStorage&&localStorage.getItem("watched_videos"))for(div='<div class="course-progress" data-width="100%" style="width: 100%;z-index: 0;"></div>',names=localStorage.getItem("watched_videos").split("|"),videos=$(".bucket-media"),_i=0,_len=videos.length;_len>_i;_i++)video=videos[_i],_ref=video.href.split("/"),filler=_ref.length>=2?__slice.call(_ref,0,_j=_ref.length-1):(_j=0,[]),link=_ref[_j++],__indexOf.call(names,link)>=0&&$(video).before(div)})();
@sankage
sankage / SegFault
Created January 28, 2013 04:59
Segmentation Fault when running a failing rspec test.
$ bundle exec rspec spec/features/deleting_leagues_spec.rb
~/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/better_errors-0.3.2/lib/better_errors/core_ext/exception.rb:9: [BUG] Segmentation fault
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
-- Control frame information -----------------------------------------------
c:0061 p:---- s:0168 b:0168 l:000167 d:000167 CFUNC :callers
c:0060 p:0072 s:0165 b:0165 l:001870 d:0015a0 LAMBDA ~/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/better_errors-0.3.2/lib/better_errors/core_ext/exception.rb:
c:0059 p:---- s:0162 b:0162 l:000161 d:000161 FINISH
c:0058 p:---- s:0160 b:0160 l:000159 d:000159 CFUNC :new
@sankage
sankage / Bundle Install
Last active December 17, 2015 08:19
Jekyll Testing { rbenv 0.4.0 } { ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0] }
➜ bundle install
Fetching gem metadata from https://rubygems.org/.......
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.4)
Installing RedCloth (4.2.9)
Using i18n (0.6.1)
Using multi_json (1.7.3)
Using activesupport (3.2.13)
Using addressable (2.3.4)
@sankage
sankage / bundle-fail.sh
Created May 23, 2013 13:58
bundle install fail
$ bundle install --path vendor/gems --binstubs
Fetching source index from https://rubygems.org/
Using rake (10.0.3)
Using i18n (0.6.2)
Using multi_json (1.6.1)
Using activesupport (3.2.12)
Using builder (3.0.4)
Using activemodel (3.2.12)
Using erubis (2.7.0)
Using journey (1.0.4)