Skip to content

Instantly share code, notes, and snippets.

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server:

@nisanthchunduru
nisanthchunduru / strip_photo_metadata.rb
Created October 1, 2017 13:50
Strip location information and additional metadata from your photos using ruby
# Install imagemagick first
# brew install imagemagick
require "shellwords"
photos_dir = "ENV['Home']/Downloads/Photos to Upload"
Dir["#{photos_dir}/**/*"].each do |file_path|
system("mogrify -strip #{Shellwords.shellescape(file_path)}")
end
@nisanthchunduru
nisanthchunduru / clone_and_restore_server_harddisk.md
Last active August 1, 2023 07:52
Clone and restore a physical server's harddisk

Clone a server's harddisk

Login to Hetzner's web interface https://robot.your-server.de/ and activate the Rescue System for the server whose disk you wish to clone.

Ssh into the Rescue System (Replace 1.2.3.4 in the command below with the actual ip address of the server)

ssh -o HostKeyAlias=hetzner-rescue.1.2.3.4 root@1.2.3.4
@nisanthchunduru
nisanthchunduru / decode_session_cookie.rb
Created August 30, 2017 13:18
Decode Session Cookie in Rails 3
@nisanthchunduru
nisanthchunduru / 176_9_149_227_interfaces
Created August 22, 2017 18:19
Missing IPv6 Configuration
root@Ubuntu-1604-xenial-64-minimal ~ # cat /etc/network/interfaces
### Hetzner Online GmbH installimage
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
iface lo inet6 loopback
auto eth0
@nisanthchunduru
nisanthchunduru / edid-decode source URL
Created July 27, 2017 19:35 — forked from OneSadCookie/edid-decode source URL
EDID decoding on the Mac, to find out what resolutions and rates the Mac is seeing reported.
http://cgit.freedesktop.org/xorg/app/edid-decode/plain/edid-decode.c
compile with:
gcc edid-decode.c -o edid-decode
get EDID from IORegistryExplorer (mine, an old 24" Apple Cinema Display, is attached).
Convert to binary with this command:
ruby -e 'File.open("edid", "wb").write(File.read("edid.txt").split.map { |s| ("0x"+s).to_i(16) }.inject("", "<<"))'
@nisanthchunduru
nisanthchunduru / README.md
Last active July 26, 2017 14:47
zsh function to quick convert an issue to a pull request

Run

issuetopr 1256

to convert issue 1256 to a pull request.

Copy the function issuetopr to your .bashrc or .zshrc to start using it.

@nisanthchunduru
nisanthchunduru / magicbell.io
Last active July 7, 2017 10:30
Example nginx configuration file for phusion passenger open source
server {
listen 443;
root /home/rails/apps/magicbell_site/current/public;
server_name magicbell.io;
# Use certificates we purchased from https://www.ssl2buy.com
ssl on;
ssl_certificate /etc/nginx/certs/magicbell.io/magicbell.io.crt;
ssl_certificate_key /etc/nginx/certs/magicbell.io/magicbell.io.key;
@nisanthchunduru
nisanthchunduru / backup_dotfiles.rb
Created June 12, 2017 10:36
Backup dotfiles that RCM already tracks
require "fileutils"
class DotfileInfo
def initialize(dotfile_info_string)
@dotfile_info_string = dotfile_info_string
end
def path
@dotfile_info_string.split(":")[0]
end
<?PHP
/**
* pingdom.php
*
* This application will check your server swap, hard drive, cpu, and MySQL conditions.
* It will then generate an appropriate XML file for a Pingdom HTTP Custom check.
*
* If any usage is above your preset thresholds, then a down message will be returned,
* indicating that your server may be under more load than usual, hopefully, providing
* a bit of advanced notice before a true failure due to lack of resources