Skip to content

Commit 2c0ad06

Browse files
authored
Devpod and silent ssh key generation (#7)
Devpod and silent ssh key generation
2 parents 53e01b2 + ca847ac commit 2c0ad06

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

README.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ We recommend using Windows Terminal for the best experience:
2525
- Download the `.wsl` file from the [releases page](https://github.com/kaelemc/wsl-clab/releases/latest).
2626
- Double click the `.wsl` file to install.
2727
- Open 'Containerlab' from the start menu, or execute `wsl -d Containerlab`
28-
- Complete the interactive shell selection. (if you plan to use [DevPod](#devpod), select `y` for SSH key copy).
28+
- Complete the interactive shell selection.
2929
- If you have Docker Desktop installed. See [Docker Desktop](#docker-desktop).
3030
- Done! you can start labbing. (see [DevPod](#devpod) for a great way to lab).
3131

@@ -115,7 +115,7 @@ Windows version: 10.0.19044.5131
115115
116116
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)**.
117117
118-
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).
118+
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.
119119
120120
If no SSH keys are found on your machine, an RSA keypair will be automatically generated.
121121
@@ -183,12 +183,7 @@ If you have Docker desktop installed. You **must** ensure the integration with t
183183
184184
Check out [this video](https://www.youtube.com/watch?v=ceDrFx2K3jE) for more info.
185185
186-
Containerlab WSL was designed to support this lab experience out of the box. Just remember the following considerations.
187-
188-
- 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.
189-
190-
> [!TIP]
191-
> 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.
186+
Containerlab WSL was designed to support this lab experience out of the box. Just remember the following consideration:
192187
193188
- 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.
194189

images/devpod_settings.png

56 KB
Loading

oobe.sh

+8-17
Original file line numberDiff line numberDiff line change
@@ -100,32 +100,27 @@ function import_ssh_keys {
100100
case $KEY_CHECK in
101101

102102
rsa*)
103-
echo -e "\033[32mRSA key found, Copying into Containerlab WSL...\033[0m"
104103
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
105-
echo $KEY >> /home/clab/.ssh/authorized_keys
104+
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
106105
;;
107106
ecdsa*)
108-
echo -e "\033[32mECDSA key found, Copying into Containerlab WSL...\033[0m"
109107
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_ecdsa.pub')
110-
echo $KEY >> /home/clab/.ssh/authorized_keys
108+
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
111109
;;
112110
ed25519*)
113-
echo -e "\033[32mED25519 key found, Copying into Containerlab WSL...\033[0m"
114111
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_ed25519.pub')
115-
echo $KEY >> /home/clab/.ssh/authorized_keys
112+
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
116113
;;
117114
False*)
118-
echo -e "\033[34mNo host keys found, Generating RSA key...\033[0m"
119-
powershell.exe -NoProfile -Command "ssh-keygen -t rsa -b 4096 -f \$env:userprofile\.ssh\id_rsa -N '\"\"'"
115+
powershell.exe -NoProfile -Command "ssh-keygen -t rsa -b 4096 -f \$env:userprofile\.ssh\id_rsa -N '\"\"'" > /dev/null 2>&1
120116
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
121-
echo $KEY >> /home/clab/.ssh/authorized_keys
122-
# powershell.exe -NoProfile -Command "Get-Content $env:userprofile\.ssh\id_rsa.pub | ssh clab@localhost -p 2222 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'"
117+
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
123118
;;
124119
*)
125-
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"
120+
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"
126121
esac
127122

128-
echo -e "\033[32mKeys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222'\033[0m"
123+
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"
129124
}
130125

131126
# We know the user clab exists from Dockerfile with UID 1000
@@ -208,11 +203,7 @@ Select zsh configuration: "
208203
esac
209204
done
210205

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

217208
exit 0
218209
fi

0 commit comments

Comments
 (0)