Skip to content

Instantly share code, notes, and snippets.

@lzwjava
Forked from xfreebird/customsshd
Created November 17, 2015 02:07
Show Gist options
  • Select an option

  • Save lzwjava/b18999dce3a7c8fa3267 to your computer and use it in GitHub Desktop.

Select an option

Save lzwjava/b18999dce3a7c8fa3267 to your computer and use it in GitHub Desktop.
A script which can be used to start a second SSHD daemon on OS X. This is an workaround for running tests using xcodebuild through ssh with Jenkins .
#!/bin/bash
INSTALL_PATH=$HOME/customkeys
SSH_HOST_KEY=$INSTALL_PATH/ssh_host_key
SSH_HOST_RSA_KEY=$INSTALL_PATH/ssh_host_rsa_key
SSH_HOST_DSA_KEY=$INSTALL_PATH/ssh_host_dsa_key
SSHD_PORT=50111
SSH_AUTHORIZED_KEYS_PATH="$HOME/.ssh/authorized_keys"
[ ! -f $SSH_HOST_KEY ] && ssh-keygen -q -t rsa1 -f $SSH_HOST_KEY -N "" -C "" < /dev/null > /dev/null 2> /dev/null
[ ! -f $SSH_HOST_RSA_KEY ] && ssh-keygen -q -t rsa -f $SSH_HOST_RSA_KEY -N "" -C "" < /dev/null > /dev/null 2> /dev/null
[ ! -f $SSH_HOST_DSA_KEY ] && ssh-keygen -q -t dsa -f $SSH_HOST_DSA_KEY -N "" -C "" < /dev/null > /dev/null 2> /dev/null
#add you public rsa key here, the authentication is ssh key based
CUSTOM_ID_RSA_PUBKEY="ssh-rsa AAAAB3NzaC1yc2dfgdfgDAQABAAABAQDRGnX9NX4K/D3Ex5NF514AyUxQCu/+nJnjyZudY5+dsfsdfewrwedgdfg/+MCTCQ6pO0RQ42dH5P41bBD5nju9yDyfK6pfUz89vwqwC5HtAOC27VWU/dfgdfg/3B1jlR5i7zzUUmMojSNZTRIFy/dffgdg/ICLObc6kwF4hSdGCpdbzDpLyCXSDQDjAJbBb//cgB4gqBcv3Nc7sh3woT7J9JH6aHFAgmn5R5dwL3P [email protected]"
#insert the key if it is not in authorized_keys
function verifyPubKey()
{
if [ -f "$SSH_AUTHORIZED_KEYS_PATH" ];
then
PUBKEYEXISTS=`grep -q "$CUSTOM_ID_RSA_PUBKEY" "$SSH_AUTHORIZED_KEYS_PATH"`
if [[ $? -eq 1 ]]
then
injectPubKey
fi
else
injectPubKey
fi
}
function injectPubKey()
{
echo "$CUSTOM_ID_RSA_PUBKEY" >> "$SSH_AUTHORIZED_KEYS_PATH"
chmod 600 "$SSH_AUTHORIZED_KEYS_PATH"
}
function runSSHD() {
/usr/sbin/sshd -D -p $SSHD_PORT -h $SSH_HOST_KEY -h $SSH_HOST_RSA_KEY -h $SSH_HOST_DSA_KEY -o UsePam=yes -o Protocol=1,2 -o PubkeyAuthentication=yes -o RSAAuthentication=yes
}
#hide terminal window
osascript -e 'tell application "Finder"' -e 'set visible of process "Terminal" to false' -e 'end tell'
verifyPubKey
echo $'\e[5m''DO NOT CLOSE THIS WINDOW'$'\e[25m'
while :
do
runSSHD
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment