Skip to content

Commit

Permalink
Devpod and silent ssh key generation (#7)
Browse files Browse the repository at this point in the history
Devpod and silent ssh key generation
  • Loading branch information
FloSch62 authored Dec 8, 2024
2 parents 53e01b2 + ca847ac commit 2c0ad06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We recommend using Windows Terminal for the best experience:
- Download the `.wsl` file from the [releases page](https://github.com/kaelemc/wsl-clab/releases/latest).
- Double click the `.wsl` file to install.
- Open 'Containerlab' from the start menu, or execute `wsl -d Containerlab`
- Complete the interactive shell selection. (if you plan to use [DevPod](#devpod), select `y` for SSH key copy).
- Complete the interactive shell selection.
- If you have Docker Desktop installed. See [Docker Desktop](#docker-desktop).
- Done! you can start labbing. (see [DevPod](#devpod) for a great way to lab).

Expand Down Expand Up @@ -115,7 +115,7 @@ Windows version: 10.0.19044.5131
You will also be presented with the choice to have the Fira Code [nerd font](https://www.nerdfonts.com/font-downloads) automatically installed on your system. **We recommend you install this font (especially if using `zsh` as your shell of choice)**.
Finally you'll be asked if you want to copy your Windows SSH keys into WSL Containerlab, this is to enable passwordless SSH access. This is an integral step for [DevPod](#devpod) usage, while the default might be **not** to, we recommed you enter `y` (Yes).
Finally at the end SSH keys will be copied from your Windows host into Containerlab WSL to enable passwordless SSH. This is an integral step for [DevPod](#devpod) usage.
If no SSH keys are found on your machine, an RSA keypair will be automatically generated.
Expand Down Expand Up @@ -183,12 +183,7 @@ If you have Docker desktop installed. You **must** ensure the integration with t
Check out [this video](https://www.youtube.com/watch?v=ceDrFx2K3jE) for more info.
Containerlab WSL was designed to support this lab experience out of the box. Just remember the following considerations.
- At the Containerlab WSL setup prompt, make sure you select `Y` to copy your Windows SSH keys into WSL. If you don't have SSH keys, they will be automatically generated for you.
> [!TIP]
> If you are already past setup, and have selected `N`, Don't worry. From inside Containerlab WSL execute `/etc/oobe.sh` and you can follow the interactive prompts again. It is not recommended to change your shell selection.
Containerlab WSL was designed to support this lab experience out of the box. Just remember the following consideration:
- When using DevPod, ensure Containerlab WSL is started (it does **not** automatically launch on Windows startup), you should leave the terminal window with Containerlab WSL open in the background.
Expand Down
Binary file modified images/devpod_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 8 additions & 17 deletions oobe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,27 @@ function import_ssh_keys {
case $KEY_CHECK in

rsa*)
echo -e "\033[32mRSA key found, Copying into Containerlab WSL...\033[0m"
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
echo $KEY >> /home/clab/.ssh/authorized_keys
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
;;
ecdsa*)
echo -e "\033[32mECDSA key found, Copying into Containerlab WSL...\033[0m"
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_ecdsa.pub')
echo $KEY >> /home/clab/.ssh/authorized_keys
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
;;
ed25519*)
echo -e "\033[32mED25519 key found, Copying into Containerlab WSL...\033[0m"
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_ed25519.pub')
echo $KEY >> /home/clab/.ssh/authorized_keys
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
;;
False*)
echo -e "\033[34mNo host keys found, Generating RSA key...\033[0m"
powershell.exe -NoProfile -Command "ssh-keygen -t rsa -b 4096 -f \$env:userprofile\.ssh\id_rsa -N '\"\"'"
powershell.exe -NoProfile -Command "ssh-keygen -t rsa -b 4096 -f \$env:userprofile\.ssh\id_rsa -N '\"\"'" > /dev/null 2>&1
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
echo $KEY >> /home/clab/.ssh/authorized_keys
# powershell.exe -NoProfile -Command "Get-Content $env:userprofile\.ssh\id_rsa.pub | ssh clab@localhost -p 2222 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'"
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
;;
*)
echo "\033[34m\nCouldn't match key type, invoking Powershell may have failed. Create an issue at https://github.com/srl-labs/wsl-containerlab\033[0m"
echo "\033[34m\nSSH: Couldn't match key type, invoking Powershell may have failed. Create an issue at https://github.com/srl-labs/wsl-containerlab\033[0m"
esac

echo -e "\033[32mKeys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222'\033[0m"
echo -e "\033[32mSSH keys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222'. (Ensure Containerlab WSL is open)\033[0m"
}

# We know the user clab exists from Dockerfile with UID 1000
Expand Down Expand Up @@ -208,11 +203,7 @@ Select zsh configuration: "
esac
done

read -p "Copy Windows SSH keys for passwordless SSH access? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
import_ssh_keys
fi
import_ssh_keys

exit 0
fi
Expand Down

0 comments on commit 2c0ad06

Please sign in to comment.