Skip to content

Instantly share code, notes, and snippets.

@shichao-an
shichao-an / add_public_key.sh
Last active August 29, 2015 14:11
Add SSH public key
#!/bin/bash
# Usage:
# First, source this script:
# $ source add_public_key.sh
# Then, use the function add user:
# $ add_public_key john 'ssh-rsa very-long-hash'
add_public_key()
{
@shichao-an
shichao-an / vpnsetup.sh
Last active August 29, 2015 14:11 — forked from hwdsl2/.MOVED.md
#!/bin/sh
#
# Amazon EC2 user-data file for automatic configuration of IPsec/L2TP VPN
# on a Ubuntu server instance. Tested with 14.04 (Trusty) AND 12.04 (Precise).
# With minor modifications, this script *can also be used* on dedicated servers
# or any KVM- or XEN-based Virtual Private Server (VPS) from other providers.
#
# DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! THIS IS MEANT TO BE RUN WHEN
# YOUR AMAZON EC2 INSTANCE STARTS!
#
#!/bin/bash
#
# Author : N.Hashimoto
# E-mail : [email protected]
# Description : Verify node joining cassandra multinode cluster, and
# send alert if the number of live node is less than the specified number.
#
# ------------------------------------------------------------
# functions
# ------------------------------------------------------------
#!/bin/bash
# Setup Nagios NRPE on Amazon EC2 (Ubuntu)
apt-get update
apt-get install -y nagios-nrpe-server nagios-plugins
sleep 2
mkdir -p /etc/nagios
cat > /etc/nagios/nrpe_local.cfg <<EOF
@shichao-an
shichao-an / install_logstash_forwarder.sh
Created January 14, 2015 01:04
Install logstash-forwarder
#!/bin/bash
# Run as root
wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add -
echo 'deb http://packages.elasticsearch.org/logstashforwarder/debian stable main' | tee /etc/apt/sources.list.d/logstashforwarder.list
apt-get update
apt-get install -y logstash-forwarder
update-rc.d logstash-forwarder defaults
@shichao-an
shichao-an / restartfw.sh
Last active August 29, 2015 14:13
Restart firewall on OS X
#!/bin/bash
# Restart firewall on OS X 10.9 and 10.10
# This script only works if you already turned on your firewall
if /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate | grep 'Firewall is disabled.' > /dev/null
then
echo 'Firewall is turned off.' >&2
else
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off && sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
fi
@shichao-an
shichao-an / upload.txt
Created January 20, 2015 18:36
tail -n +1 *.dump > upload.txt
==> 530528_http_-_interface.bilibili.com_playurlappkey=1_cid=792790.dump <==
<?xml version="1.0" encoding="UTF-8"?>
<video>
<result>suee</result>
<timelength>1915660</timelength>
<framecount>34767313</framecount>
<src>400</src>
<letv-args><![CDATA[]]]></letv-args>
<from><![CDATA[sina]]></from>
<durl>
@shichao-an
shichao-an / ldap_disable_bind_anon.ldif
Created February 3, 2015 19:53
Ubuntu and LDAP: force authentication during a bind request
# ldapadd -Y EXTERNAL -H ldapi:/// -f ldap_disable_bind_anon.ldif
dn: cn=config
changetype: modify
add: olcDisallows
olcDisallows: bind_anon
dn: cn=config
changetype: modify
add: olcRequires
olcRequires: authc
@shichao-an
shichao-an / openssh-lpk.ldif
Created February 3, 2015 22:02
ldapadd -Y EXTERNAL -H ldapi:/// -f openssh-lpk.ldif
dn: cn=openssh-lpk,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: openssh-lpk
olcAttributeTypes: ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey'
DESC 'MANDATORY: OpenSSH Public key'
EQUALITY octetStringMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
olcObjectClasses: ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
DESC 'MANDATORY: OpenSSH LPK objectclass'
MAY ( sshPublicKey $ uid )
@shichao-an
shichao-an / common-auth
Created February 4, 2015 00:05
/etc/pam.d/common-auth
#
# /etc/pam.d/common-auth - authentication settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authentication modules that define
# the central authentication scheme for use on the system
# (e.g., /etc/shadow, LDAP, Kerberos, etc.). The default is to use the
# traditional Unix authentication mechanisms.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.