Skip to content

Commit

Permalink
update for ssh server (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
shunk031 authored Mar 4, 2024
1 parent 3eae36f commit 62ac75c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ if eq .chezmoi.os "linux" -}}
{{ if eq .chezmoi.osRelease.idLike "debian" -}}
{{ if eq .system "server" -}}
{{ include "../install/ubuntu/server/ssh_server.sh" }}
{{ end -}}
{{ end -}}
{{ end -}}
46 changes: 46 additions & 0 deletions install/ubuntu/server/ssh_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -Eeuo pipefail

if [ "${DOTFILES_DEBUG:-}" ]; then
set -x
fi

function install_openssh_server() {
# install openssh-server
apt-get update && apt-get install --no-install-recommends -y vim openssh-server
}

function setup_sshd() {
mkdir -p /var/run/sshd
mkdir -p /root/.ssh

sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config &&
sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config &&
sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config &&
sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config &&
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# check the /etc/ssh/sshd_config
/usr/sbin/sshd -t

# create .ssh/authorized_keys if not exists
touch ~/.ssh/authorized_keys
}

function run_sshd() {
# run sshd
/usr/sbin/sshd
}

function main() {
install_openssh_server
setup_sshd
run_sshd
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [ -f "/.dockerenv" ]; then
main
fi
fi

0 comments on commit 62ac75c

Please sign in to comment.