From ed1a4b5292e99ec3811ad37573b92279fdaadbfc Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Sat, 18 May 2024 06:02:42 +0000 Subject: [PATCH] Fixed SSH on macOS for /etc/services --- home/.chezmoi.yaml.tmpl | 2 +- .../universal/run_after_01-pre-install.sh.tmpl | 16 +++++++++++++--- home/private_dot_ssh/private_config.tmpl | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/home/.chezmoi.yaml.tmpl b/home/.chezmoi.yaml.tmpl index 351fe36d..fd4425eb 100644 --- a/home/.chezmoi.yaml.tmpl +++ b/home/.chezmoi.yaml.tmpl @@ -158,7 +158,7 @@ data: allowTCPForwarding: no allowUsers: {{ env "USER" }} endlesshPort: 22 - port: 2214 + port: 8169 vpn: excludedSubnets: - 10.0.0.0/24 diff --git a/home/.chezmoiscripts/universal/run_after_01-pre-install.sh.tmpl b/home/.chezmoiscripts/universal/run_after_01-pre-install.sh.tmpl index d75a771d..77fc375e 100644 --- a/home/.chezmoiscripts/universal/run_after_01-pre-install.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_after_01-pre-install.sh.tmpl @@ -325,10 +325,20 @@ configureSSHD() { ### Restart SSH server if [ -d /Applications ] && [ -d /System ]; then ### macOS + if [ -f /etc/services ]; then + logg info 'Updating SSH configuration in /etc/services to point to port {{ .host.ssh.port }}' + sudo sed -i.bak 's/ 22\/udp/ {{ .host.ssh.port }}\/udp/' /etc/services + sudo sed -i.bak 's/ 22\/tcp/ {{ .host.ssh.port }}\/tcp/' /etc/services + sudo rm -f /etc/services.bak + fi logg info 'Running sudo systemsetup -setremotelogin on' && sudo systemsetup -setremotelogin on > /dev/null - logg info 'Running sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist' && sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist 2> /dev/null - logg info 'Running sudo launchctl stop com.openssh.sshd' && sudo launchctl stop com.openssh.sshd - logg info 'Running sudo launchctl start com.openssh.sshd' && sudo launchctl start com.openssh.sshd && logg info 'Successfully ran launchctl start com.openssh.sshd' + if sudo launchctl list | grep 'com.openssh.sshd' > /dev/null; then + logg info 'Unloading previous com.openssh.sshd configuration' + sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist + fi + logg info 'Running sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist (Latest)' && sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist + logg info 'Running sudo launchctl stop com.openssh.sshd (High Sierra - errors muted)' && sudo launchctl stop com.openssh.sshd 2> /dev/null + logg info 'Running sudo launchctl start com.openssh.sshd (High Sierra - errors muted)' && sudo launchctl start com.openssh.sshd 2> /dev/null && logg info 'Successfully ran launchctl start com.openssh.sshd' else ### Linux logg info 'Enabling the sshd service' diff --git a/home/private_dot_ssh/private_config.tmpl b/home/private_dot_ssh/private_config.tmpl index 567b7867..53210fe0 100644 --- a/home/private_dot_ssh/private_config.tmpl +++ b/home/private_dot_ssh/private_config.tmpl @@ -29,6 +29,10 @@ Host gitlab.com Host github.com UpdateHostKeys no IdentityFile ~/.ssh/id_rsa +Host macbook-pro + User {{ .user.username }} + Hostname ssh-macbook-pro.{{ .host.domain }} + ProxyCommand /opt/homebrew/bin/cloudflared access ssh --hostname %h {{ if (lookPath "fig") -}} Match all Include ~/.fig/ssh