aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-02-11 15:14:15 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-02-11 15:17:12 +0100
commit687539d847ff54d17a4360aaccab580ba9000c3c (patch)
treefed5a9961b079103d14bd68f01712783eae84a20 /example
parent52650fffc2f9e7bd279a9007e4aced78dc78a970 (diff)
downloadsocket_wrapper-687539d847ff54d17a4360aaccab580ba9000c3c.tar.gz
socket_wrapper-687539d847ff54d17a4360aaccab580ba9000c3c.tar.xz
socket_wrapper-687539d847ff54d17a4360aaccab580ba9000c3c.zip
Add an example using openssh sshd and ssh.
Diffstat (limited to 'example')
-rwxr-xr-xexample/openssh.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/example/openssh.sh b/example/openssh.sh
new file mode 100755
index 0000000..abf557e
--- /dev/null
+++ b/example/openssh.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+SSH_DIRECTORY=$(mktemp -d)
+mkdir ${SSH_DIRECTORY}/swrap
+
+cleanup_and_exit () {
+ trap EXIT
+ test -z "$1" && set 0
+
+ kill -TERM $(< ${SSH_DIRECTORY}/sshd.pid)
+ rm -rf ${SSH_DIRECTORY}
+
+ exit $1
+}
+
+# Setup exit handler
+trap cleanup_and_exit SIGINT SIGTERM
+
+echo Generating ${SSH_DIRECTORY}/ssh_host_key.
+ssh-keygen -t rsa1 -b 2048 -f ${SSH_DIRECTORY}/ssh_host_key -N '' 2>/dev/null
+echo Generating ${SSH_DIRECTORY}/ssh_host_dsa_key.
+ssh-keygen -t dsa -f ${SSH_DIRECTORY}/ssh_host_dsa_key -N '' 2>/dev/null
+echo Generating ${SSH_DIRECTORY}/ssh_host_rsa_key.
+ssh-keygen -t rsa -b 2048 -f ${SSH_DIRECTORY}/ssh_host_rsa_key -N '' 2>/dev/null
+echo Generating ${SSH_DIRECTORY}/ssh_host_ecdsa_key.
+ssh-keygen -t ecdsa -b 256 -f ${SSH_DIRECTORY}/ssh_host_ecdsa_key -N '' 2>/dev/null
+
+# Create sshd_config file
+cat > ${SSH_DIRECTORY}/sshd_config << EOT
+Port 22
+ListenAddress 127.0.0.10
+HostKey ${SSH_DIRECTORY}/ssh_host_key
+HostKey ${SSH_DIRECTORY}/ssh_host_rsa_key
+HostKey ${SSH_DIRECTORY}/ssh_host_dsa_key
+HostKey ${SSH_DIRECTORY}/ssh_host_ecdsa_key
+Subsystem sftp /usr/lib/ssh/sftp-server
+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
+PidFile ${SSH_DIRECTORY}/sshd.pid
+EOT
+
+export SOCKET_WRAPPER_DIR="${SSH_DIRECTORY}/swrap"
+export SOCKET_WRAPPER_DEFAULT_IFACE=10
+
+echo
+echo "Starting SSHD with SOCKET_WRAPPER_DIR=${SSH_DIRECTORY}/swrap ..."
+LD_PRELOAD=libsocket_wrapper.so /usr/sbin/sshd -f ${SSH_DIRECTORY}/sshd_config -e 2> ${SSH_DIRECTORY}/sshd_log || cleanup_and_exit 1
+echo "done"
+
+echo
+echo "Connecting to the 127.0.0.10 ssh server using ssh binary."
+echo "You can check the sshd log file at ${SSH_DIRECTORY}/sshd_log."
+echo "If you logout sshd will be stopped and the environment cleaned up."
+ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 127.0.0.10
+
+cleanup_and_exit 0