Auto setup the SSH connection if the devcontainer has not been initialised.
This commit is contained in:
parent
bde737b037
commit
d16d8c94ac
1 changed files with 18 additions and 2 deletions
|
|
@ -21,7 +21,23 @@ if ! ssh_port="$(${CONTAINER} inspect --format '{{ (index (index .NetworkSetting
|
|||
exit 1
|
||||
fi
|
||||
|
||||
ssh -o UserKnownHostsFile=/dev/null \
|
||||
-o StrictHostKeyChecking=false \
|
||||
ignore_hostkey=("-oUserKnownHostsFile=/dev/null" "-oStrictHostKeyChecking=false")
|
||||
|
||||
if ! ssh "${ignore_hostkey[@]}" -oPasswordAuthentication=no -p "${ssh_port}" -T dev@localhost 'exit'; then
|
||||
docker exec -it "${container_id}" /bin/bash -c 'echo "dev:dev" | chpasswd'
|
||||
echo "[+] Changed password of container user to 'dev'"
|
||||
|
||||
if command -v sshpass &>/dev/null; then
|
||||
sshpass -p"dev" ssh-copy-id -p "${ssh_port}" dev@localhost
|
||||
elif command -v expect &>/dev/null; then
|
||||
expect -c "spawn $(which ssh-copy-id) -p ${ssh_port} dev@localhost; interact -o -nobuffer -re .*assword.* return; send \"dev\r\n\"; send -- \"\r\"; expect eof;"
|
||||
else
|
||||
echo "[?] Could not find application to automatically copy SSH key."
|
||||
echo " Please enter the password 'dev' manually below."
|
||||
ssh-copy-id -p "${ssh_port}" dev@localhost
|
||||
fi
|
||||
fi
|
||||
|
||||
ssh "${ignore_hostkey[@]}" \
|
||||
-p "${ssh_port}" \
|
||||
dev@localhost "$@"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue