SSH to my NixOS
source link: https://dannypsnl.github.io/blog/2022/01/21/cs/ssh-to-my-nixos/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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.
Configure Router
First thing is let router preserves a DHCP IP for NixOS MAC, where to configure it is depends on your router.
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;
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>
Final
Now everything is ready, I can ssh to my NixOS desktop. Then I upgrade my NixOS to 21.11 remotely, it's fun!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK