SSH to my NixOS
Since my macOS using arm64, I can't develop x64 apps on my NixOS, at least it's not as simple as on native machine. Thus, I always have a good reason to ssh to my NixOS and work on it, but I never do that since I'm lazy! This is a journey about how I be able to ssh to my NixOS desktop.
1. Configure Router
First thing is let router preserves a DHCP IP for NixOS MAC, where to configure it is depends on your router.
2. Use DHCP
Modify /etc/nixos/configuration.nix
, ensure the NIC is using DHCP, and
then run nixos-rebuild switch
should get a static internal IP now.
networking.interfaces.<your NIC>.useDHCP = true;
3. Enable SSH
The following code enable SSH for NixOS.
users.users.<user name> = { # ... openssh.authorizedKeys.keys = [ "<your local public key>" ]; } services.openssh.enable = true;
An example about local public key is id_rsa.pub
, then put the
following config into ~/.ssh/config
in your local machine.
Host <IP> HostName <IP> User <username> Port <ssh port>
4. Final
Now everything is ready, I can ssh to my NixOS desktop. Then I upgrade my NixOS to 21.11 remotely, it's fun!