- 06.03.2020 - added zsh function that works for WSL
- 04.21.2020 - updated mac os x code to work with zsh and improved instructions.
- 01.02.2020 - added Windows Subsystem for Linux and broke out each OS into its own section for easy copy and paste
- 12.10.2019 - added support for Rancher 1.6 tar.gz files (requires gtar on mac)
- 12.06.2019 - made command lazier by not requiring user to paste the IP.
Quick bash function to make my life easier when sshing into Rancher nodes. Make sure to update your default web browser download directory by modifying line 2 of the script. For mac: brew install findutils
function lssh {
PROSSH_DOWNLOAD_DIR="${HOME}/Downloads"
PROSSH_FILE=$(gfind ${PROSSH_DOWNLOAD_DIR} -type f -size -500k -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
PROSSH_USER=$1
PROSSH_IP=$(pbpaste)
if [ -z "${PROSSH_USER}" ]; then
PROSSH_USER='ubuntu'
fi
[[ ${PROSSH_FILE} == *.zip ]] && unzip -p "${PROSSH_FILE}" "*id_rsa" > ${HOME}/.ssh/prossh
[[ ${PROSSH_FILE} == *.tar.gz ]] && gtar -Oxf "${PROSSH_FILE}" --wildcards "*id_rsa" > ${HOME}/.ssh/prossh
chmod 600 ~/.ssh/prossh
echo ${PROSSH_FILE} extracted, now sshing into box!
ssh -i ${HOME}/.ssh/prossh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null ${PROSSH_USER}@${PROSSH_IP}
}
function lssh {
PROSSH_DOWNLOAD_DIR='~/Downloads'
PROSSH_FILE=$(find ${PROSSH_DOWNLOAD_DIR} -type f -size -500k -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
PROSSH_USER=$1
PROSSH_IP=$(xclip -o)
if [ -z "${PROSSH_USER}" ]; then
PROSSH_USER='ubuntu'
fi
[[ ${PROSSH_FILE} == *.zip ]] && unzip -p "${PROSSH_FILE}" *id_rsa > ~/.ssh/prossh
[[ ${PROSSH_FILE} == *.tar.gz ]] && gtar -Oxf "${PROSSH_FILE}" --wildcards "*id_rsa" > ~/.ssh/prossh
chmod 600 ~/.ssh/prossh
echo ${PROSSH_FILE} extracted, now sshing into box!
ssh -i ~/.ssh/prossh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null ${PROSSH_USER}@${PROSSH_IP}
}
function lssh {
PROSSH_DOWNLOAD_DIR='/mnt/c/Users/<CHANGE THIS TO YOUR USERNAME>/Downloads/'
PROSSH_FILE=$(find ${PROSSH_DOWNLOAD_DIR} -type f -size -500k -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
PROSSH_USER=$1
PROSSH_IP=$(powershell.exe -command "Get-Clipboard")
if [ -z "${PROSSH_USER}" ]; then
PROSSH_USER='ubuntu'
fi
[[ ${PROSSH_FILE} == *.zip ]] && unzip -p "${PROSSH_FILE}" *id_rsa > ~/.ssh/prossh
[[ ${PROSSH_FILE} == *.tar.gz ]] && gtar -Oxf "${PROSSH_FILE}" --wildcards "*id_rsa" > ~/.ssh/prossh
chmod 600 ~/.ssh/prossh
echo ${PROSSH_FILE} extracted, now sshing into box!
ssh -i ~/.ssh/prossh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null ${PROSSH_USER}@${PROSSH_IP}
}
function lssh {
PROSSH_DOWNLOAD_DIR='/mnt/c/Users/<CHANGE THIS TO YOUR USERNAME>/Downloads/'
PROSSH_FILE=$(find ${PROSSH_DOWNLOAD_DIR} -type f -size -500k -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
PROSSH_USER=$1
PROSSH_IP=$(powershell.exe -command "Get-Clipboard")
if [ -z "${PROSSH_USER}" ]; then
PROSSH_USER='ubuntu'
fi
[[ ${PROSSH_FILE} == *.zip ]] && unzip -p "${PROSSH_FILE}" \*id_rsa > ~/.ssh/prossh
[[ ${PROSSH_FILE} == *.tar.gz ]] && tar -Oxf "${PROSSH_FILE}" --wildcards "*id_rsa" > ~/.ssh/prossh
chmod 600 ~/.ssh/prossh
echo ${PROSSH_FILE} extracted, now sshing into box!
ssh -i ~/.ssh/prossh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -l ${PROSSH_USER//[[:space:]]/} "${PROSSH_IP//[[:space:]]/}"
}
-
Copy and paste the function to your ~/.bash_profile or ~/.bashrc
-
Logout and log back in or source your file for changes to take effect in your current terminal
-
Download an ssh key for a node you want to log into, ensure that it goes to ~/Downloads and is the most recently created file
-
Copy the IP of the node
-
On the terminal
lssh [user]
-
This will log you into the node by extracting the most recently downloaded file's id_rsa and sshing to the IP in your clipboard and user you specify. If no user is specified then it will assume ubuntu.