@@ -81,12 +81,61 @@ function install_fonts {
81
81
fi
82
82
}
83
83
84
+ function import_ssh_keys {
85
+ KEY_CHECK=$( powershell.exe -NoProfile -Command '
86
+ $key_types = @("rsa", "ecdsa", "ed25519")
87
+
88
+ foreach ( $type in $key_types )
89
+ {
90
+ if( Test-Path $env:userprofile\.ssh\id_$type.pub )
91
+ {
92
+ return $type
93
+ }
94
+ }
95
+ Write-Output False
96
+ ' )
97
+
98
+ mkdir -p /home/clab/.ssh
99
+
100
+ case $KEY_CHECK in
101
+
102
+ rsa* )
103
+ echo -e " \033[32mRSA key found, Copying into Containerlab WSL...\033[0m"
104
+ KEY=$( powershell.exe -NoProfile -Command ' Get-Content $env:userprofile\.ssh\id_rsa.pub' )
105
+ echo $KEY >> /home/clab/.ssh/authorized_keys
106
+ ;;
107
+ ecdsa* )
108
+ echo -e " \033[32mECDSA key found, Copying into Containerlab WSL...\033[0m"
109
+ KEY=$( powershell.exe -NoProfile -Command ' Get-Content $env:userprofile\.ssh\id_ecdsa.pub' )
110
+ echo $KEY >> /home/clab/.ssh/authorized_keys
111
+ ;;
112
+ ed25519* )
113
+ echo -e " \033[32mED25519 key found, Copying into Containerlab WSL...\033[0m"
114
+ KEY=$( powershell.exe -NoProfile -Command ' Get-Content $env:userprofile\.ssh\id_ed25519.pub' )
115
+ echo $KEY >> /home/clab/.ssh/authorized_keys
116
+ ;;
117
+ 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 '\"\" '"
120
+ 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'"
123
+ ;;
124
+ * )
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"
126
+ esac
127
+
128
+ echo -e " \033[32mKeys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222'\033[0m"
129
+ }
130
+
84
131
# We know the user clab exists from Dockerfile with UID 1000
85
132
if getent passwd " $DEFAULT_UID " > /dev/null ; then
86
133
87
134
echo -e " \033[32mWelcome to Containerlab's WSL distribution\033[0m"
88
135
89
136
echo " cd ~" >> /home/clab/.bashrc
137
+
138
+ echo " echo clab | sudo -S mkdir -p /run/docker/netns" >> /home/clab/.bashrc
90
139
91
140
PS3="
92
141
Please select which shell you'd like to use: "
@@ -159,6 +208,12 @@ Select zsh configuration: "
159
208
esac
160
209
done
161
210
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
216
+
162
217
exit 0
163
218
fi
164
219
0 commit comments