mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-28 21:21:04 +01:00
Updated SSH access (markdown)
parent
8c6f52e593
commit
e566a6b1b0
1 changed files with 42 additions and 1 deletions
|
|
@ -16,3 +16,44 @@ We will provide a module for the sshd config and service in the future to simpli
|
||||||
It is recommended to source `~/.nix-profile/etc/profile.d/nix-on-droid-session-init.sh` from `~/.profile`.
|
It is recommended to source `~/.nix-profile/etc/profile.d/nix-on-droid-session-init.sh` from `~/.profile`.
|
||||||
|
|
||||||
Furthermore the login shell is not recognized yet, so you may start your desired shell manually once logged via ssh.
|
Furthermore the login shell is not recognized yet, so you may start your desired shell manually once logged via ssh.
|
||||||
|
|
||||||
|
## nix-on-droid config
|
||||||
|
|
||||||
|
You can also use this snippet to ease the manual setup process:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
let
|
||||||
|
sshdTmpDirectory = "${config.user.home}/sshd-tmp";
|
||||||
|
sshdDirectory = "${config.user.home}/sshd";
|
||||||
|
pathToPubKey = "...";
|
||||||
|
port = 8022;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
build.activation.sshd = ''
|
||||||
|
$DRY_RUN_CMD mkdir $VERBOSE_ARG --parents "${config.user.home}/.ssh"
|
||||||
|
$DRY_RUN_CMD cat ${pathToPubKey} > "${config.user.home}/.ssh/authorized_keys"
|
||||||
|
|
||||||
|
if [[ ! -d "${sshdDirectory}" ]]; then
|
||||||
|
$DRY_RUN_CMD rm $VERBOSE_ARG --recursive --force "${sshdTmpDirectory}"
|
||||||
|
$DRY_RUN_CMD mkdir $VERBOSE_ARG --parents "${sshdTmpDirectory}"
|
||||||
|
|
||||||
|
$VERBOSE_ECHO "Generating host keys..."
|
||||||
|
$DRY_RUN_CMD ${pkgs.openssh}/bin/ssh-keygen -t rsa -b 4096 -f "${sshdTmpDirectory}/ssh_host_rsa_key" -N ""
|
||||||
|
|
||||||
|
$VERBOSE_ECHO "Writing sshd_config..."
|
||||||
|
$DRY_RUN_CMD echo -e "HostKey ${sshdDirectory}/ssh_host_rsa_key\nPort ${toString port}\n" > "${sshdTmpDirectory}/sshd_config"
|
||||||
|
|
||||||
|
$DRY_RUN_CMD mv $VERBOSE_ARG "${sshdTmpDirectory}" "${sshdDirectory}"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
|
environment.packages = [
|
||||||
|
(pkgs.writeScriptBin "sshd-start" ''
|
||||||
|
#!${pkgs.runtimeShell}
|
||||||
|
|
||||||
|
echo "Starting sshd in non-daemonized way on port ${toString port}"
|
||||||
|
${pkgs.openssh}/bin/sshd -f "${sshdDirectory}/sshd_config" -D
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue