Last active
May 31, 2022 07:32
-
-
Save xfreebird/93901ce603cbe087329e 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 .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INSTALL_PATH="$HOME/scripts" | |
SCRIPT_PATH="$INSTALL_PATH/customsshd" | |
LAUNCHCTL_PATH="$HOME/Library/LaunchAgents/com.my.customsshd.plist" | |
SSH_KEYS_INSTALL_PATH=$HOME/customkeys | |
SSH_HOST_KEY=$SSH_KEYS_INSTALL_PATH/ssh_host_key | |
SSH_HOST_RSA_KEY=$SSH_KEYS_INSTALL_PATH/ssh_host_rsa_key | |
SSH_HOST_DSA_KEY=$SSH_KEYS_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 | |
} | |
function installLaunchAgent() | |
{ | |
cat > "$LAUNCHCTL_PATH" << EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.my.customsshd</string> | |
<key>Program</key> | |
<string>$SCRIPT_PATH</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/tmp/customsshd.log</string> | |
<key>StandardErrorPath</key> | |
<string>/tmp/customsshd_err.log</string> | |
</dict> | |
</plist> | |
EOF | |
launchctl load -w "$LAUNCHCTL_PATH" | |
echo "customsshd has been installed" | |
} | |
#if anything passed as argument, just install the script | |
#example: | |
#./customsshd install | |
if [ $# -eq 1 ] | |
then | |
installLaunchAgent | |
exit 0 | |
fi | |
verifyPubKey | |
while : | |
do | |
runSSHD | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
thank you very much for this tool ... I have a problem with it and I think I do not have it configured correctly.
Maybe you can help me out?
I have the following setup:
I performed the following steps:
SCRIPT_PATH="$INSTALL_PATH/customsshd" and moved the script to the later
Test target MyApp Tests encountered an error (Timed out waiting 120 seconds for simulator to boot, current state is 1
(the simulator opens, but the app is not installed)
Is there something I forgot or configured wrongly?
Thank you very much,
mgehlen