Created
August 8, 2021 01:36
-
-
Save zhanghai/335f50fc91989869cd9e366f6eef9473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
config_directory="$(dirname "$(realpath "$0")")" | |
port=2222 | |
while [[ "$#" -gt 0 ]]; do | |
case "$1" in | |
-c|--config-directory) | |
config_directory="$2" | |
shift | |
shift | |
;; | |
-p|--port) | |
port="$2" | |
shift | |
shift | |
;; | |
esac | |
done | |
if [[ ! -f "${config_directory}/host_key" ]]; then | |
ssh-keygen -t rsa -b 4096 -f "${config_directory}/host_key" -N '' | |
fi | |
cat <<EOF >"${config_directory}/sshd_config" | |
Port ${port} | |
HostKey ${config_directory}/host_key | |
AuthorizedKeysFile ${config_directory}/authorized_keys | |
ChallengeResponseAuthentication no | |
UsePAM yes | |
AllowAgentForwarding no | |
AllowTcpForwarding no | |
PrintMotd no | |
PidFile ${config_directory}/sshd.pid | |
Subsystem sftp internal-sftp | |
ForceCommand internal-sftp | |
EOF | |
echo "Note: You may want to manually kill the remaining sshd processes for active sessions after you exit the main sshd process." | |
"$(type -p sshd)" -Def "${config_directory}/sshd_config" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment