283 lines
7.3 KiB
Org Mode
283 lines
7.3 KiB
Org Mode
#+title: windows11 setup
|
|
# org-publish options
|
|
# ^:{} require a_{b} before assuming that b should be subscripted.
|
|
# without this option a_b will automatically subscript b.
|
|
#+options: ^:{}
|
|
#
|
|
# emacs-specific options
|
|
#+startup: showall
|
|
#
|
|
# html exporter options
|
|
#+setupfile: ../ext/fniessen/theme-readtheorg.setup
|
|
#+language: en
|
|
# +infojs_opt: view:showall mouse:#ffc0c0 toc:nil ltoc:nil path:/web/ext/orginfo/org-info.js
|
|
# +html_head: <link rel="stylesheet" type="text/css" href="/web/css/notebook.css" />
|
|
#+html_link_home: /web/index.html
|
|
|
|
* Introduction
|
|
Notes on setup for my primary desktop
|
|
|
|
#+begin_src dot :file img/windows.svg :exports results :cmdline -Tsvg
|
|
digraph {
|
|
size="8,8"
|
|
rankdir=LR;
|
|
subgraph cluster_laptop {
|
|
label="roly-laptop-21";
|
|
terminal;
|
|
}
|
|
subgraph cluster_w11 {
|
|
label="roly-desktop-23";
|
|
w11_sshd
|
|
subgraph cluster_wsl {
|
|
label="wsl2";
|
|
wsl_sshd [tooltip="listens on port 2022 to avoid collision with windows sshd"];
|
|
}
|
|
}
|
|
terminal -> w11_sshd [label="ssh Rcony@roly-desktop-23"];
|
|
w11_sshd -> wsl_sshd [label="ssh -p 2022 roland@localhost"];
|
|
terminal -> wsl_sshd [label="ssh roly-desktop-23-wsl\n(via ProxyJump)"];
|
|
}
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
[[file:img/windows.svg]]
|
|
|
|
** Remap Keyboard
|
|
Use PowerToys (free from MS)
|
|
Keyboard Manager allows directly remapping keys
|
|
|
|
Remap:
|
|
| from | to |
|
|
|--------------+-------------|
|
|
| caps lock | ctrl (left) |
|
|
| ctrl (right) | caps lock |
|
|
|
|
without the second mapping, if caps lock gets enabled there's no easy way to cancel it.
|
|
|
|
** Setup OpenSSH
|
|
|
|
*** SSH to windows
|
|
|
|
**** Enable windows ssh server from system settings.
|
|
|
|
To verify running:
|
|
1. open admin powershell
|
|
|
|
#+begin_example
|
|
> Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
|
|
|
|
Name : OpenSSH.Client~~~~0.0.1.0
|
|
State : Installed
|
|
|
|
Name : OpenSSH.Server~~~~0.0.1.0
|
|
State : NotPresent
|
|
#+end_example
|
|
|
|
above shows SSH server *not* running.
|
|
|
|
2. enable SSH server (this takes a few minutes):
|
|
|
|
#+begin_example
|
|
> Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
|
|
|
|
Path :
|
|
Online : True
|
|
RestartNeeded : False
|
|
#+end_example
|
|
|
|
3. Start SSH service
|
|
|
|
#+begin_example
|
|
> Start-Service sshd
|
|
#+end_example
|
|
|
|
4. configure to start automatically on boot
|
|
|
|
#+begin_example
|
|
> Set-Service -Name sshd -StartupType 'Automatic'
|
|
#+end_example
|
|
|
|
5. =ssh-agent= also needs assistance
|
|
|
|
#+begin_example
|
|
> Get-Service ssh-agent
|
|
|
|
Status Name DisplayName
|
|
------ ---- -----------
|
|
Stopped ssh-agent OpenSSH Authentication Agent
|
|
#+end_example
|
|
|
|
set it to start manually (whenever someone invokes =ssh-agent=)
|
|
#+begin_example
|
|
> Get-Service -Name ssh-agent | Set-Service -StartupType Manual
|
|
#+end_example
|
|
|
|
**** passwordless login
|
|
|
|
1. public key in:
|
|
=C:\Users\<myusername>\.ssh\authorized_keys= if non-administrator account
|
|
=C:\ProgramData\ssh\administrators_authorized_keys= if administrator account.
|
|
|
|
Note that =C:\ProgramData= is hidden. Can change directory to it in powershell,
|
|
but it won't normally appear in file explorer.
|
|
|
|
2. relax settings in
|
|
=C:\ProgramData\ssh\sshd_config=.
|
|
|
|
we want to uncomment a few disabled-by-default features:
|
|
#+begin_example
|
|
PubkeyAuthentication yes
|
|
AllowAgentForwarding yes
|
|
AllowTcpForwarding yes
|
|
#+end_example
|
|
|
|
*** SSH to WSL2
|
|
|
|
in wsl2 shell:
|
|
|
|
1. install openssh:
|
|
|
|
#+begin_example
|
|
$ sudo apt-get install openssh-server
|
|
#+end_example
|
|
|
|
2. default config listens on port 22:
|
|
|
|
#+begin_example
|
|
$ cat /etc/ssh/sshd_config | grep -i port
|
|
#Port 22
|
|
#+end_example
|
|
|
|
listen on port 2022 instead,
|
|
since =sshd= run by windows11 occupies port 22 already
|
|
|
|
#+begin_example
|
|
$ sudo sed -i -E 's:^#Port.*$:Port 2022:' /etc/ssh/sshd_config
|
|
$ cat /etc/ssh/sshd_config | grep -i port
|
|
#Port 2022
|
|
#+end_example
|
|
|
|
3. start ssh service
|
|
|
|
NOTE: relies on systemd. older WSL2 (sometime before 2023) didn't have systemd,
|
|
so might need to upgrade first
|
|
|
|
#+begin_example
|
|
$ sudo systemctl enable ssh
|
|
Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
|
|
$ sudo systemctl stop ssh # in case already running, perhaps on wrong port
|
|
$ sudo systemctl start ssh
|
|
#+end_example
|
|
|
|
should be able to see it running now
|
|
#+begin_example
|
|
$ ps -A | grep sshd
|
|
20139 ? 00:00:00 sshd
|
|
#+end_example
|
|
|
|
and verify listening on the right port
|
|
#+begin_example
|
|
$ netstat -a -n | grep tcp
|
|
tcp 0 0 0.0.0.0:2022 0.0.0.0:* LISTEN
|
|
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
|
|
tcp6 0 0 :::2022 :::* LISTEN
|
|
#+end_example
|
|
|
|
verify wsl2 can ssh to itself
|
|
#+begin_example
|
|
$ ssh -p 2022 localhost
|
|
#+end_example
|
|
|
|
*** SSH from external host
|
|
|
|
We have alternatives
|
|
|
|
**** ssh proxy jump
|
|
|
|
in external host's =~/.ssh/ssh_config=:
|
|
|
|
#+begin_example
|
|
# my windows desktop
|
|
Host roly-desktop-23
|
|
User Rcony
|
|
HostName 192.168.1.10
|
|
|
|
# wsl hosted from windows
|
|
Host roly-desktop-23-wsl
|
|
User roland
|
|
HostName localhost
|
|
Port 2022
|
|
ProxyJump roly-desktop-23
|
|
#+end_example
|
|
|
|
Then from external host:
|
|
|
|
#+begin_example
|
|
$ eval $(ssh-agent -s)
|
|
$ ssh-add
|
|
..passphrase..
|
|
$ ssh roly-desktop-23-wsl
|
|
roland@roly-desktop-23:~$
|
|
#+end_example
|
|
|
|
Note this only works once passwordless ssh to windows is working
|
|
|
|
**** forward WSL-2 port
|
|
|
|
NOTE: Have not had success with ssh port forwarding yet, at least as of 25dec2024.
|
|
|
|
In admin powershell:
|
|
|
|
#+begin_example
|
|
netsh interface portproxy add v4tov4 `
|
|
listenaddress=192.168.1.10 `
|
|
listenport=2322 `
|
|
connectaddress=172.17.64.1 `
|
|
connectport=2022
|
|
#+end_example
|
|
|
|
connect_port :: wsl ssh listening on this port
|
|
|
|
To rediscover wsl listening on port (from wsl prompt):
|
|
|
|
#+begin_example
|
|
$ netstat -l | grep 2022
|
|
tcp 0 0 0.0.0.0:2022 0.0.0.0:* LISTEN
|
|
tcp6 0 0 [::]:2022 [::]:* LISTEN
|
|
#+end_example
|
|
|
|
To rediscover wsl VM's ip address according to windows11:
|
|
|
|
In powershell:
|
|
|
|
#+begin_example
|
|
> ipconfig
|
|
|
|
Windows IP Configuration
|
|
...
|
|
|
|
Ethernet adapter vEthernet (WSL (Hyper-V firewall)):
|
|
|
|
Connection-specific DNS Suffix . :
|
|
Link-local IPv6 Address . . . . . : fe80::d8b4:eb39:67da:da8f%14
|
|
IPv4 Address. . . . . . . . . . . : 172.17.64.1
|
|
Subnet Mask . . . . . . . . . . . : 255.255.240.0
|
|
Default Gateway . . . . . . . . . :
|
|
|
|
#+end_example
|
|
|
|
The address we want is under 'IPv4 Address'. This IP is local
|
|
to the windows11 instance, it's not visible outside that host.
|
|
|
|
To see windows11 ports in use:
|
|
|
|
in powershell:
|
|
#+begin_example
|
|
> netstat -a
|
|
|
|
Active Connections
|
|
|
|
Proto Local Address Foreign Address State
|
|
TCP 0.0.0.0:22 roly-desktop-23 LISTENING
|
|
|
|
#+end_example
|