Skip to content

Instantly share code, notes, and snippets.

@bombsimon
Last active September 8, 2019 21:16
Show Gist options
  • Save bombsimon/215f879c86c6663f900cc860a3c69c0c to your computer and use it in GitHub Desktop.
Save bombsimon/215f879c86c6663f900cc860a3c69c0c to your computer and use it in GitHub Desktop.
Disable SSH login
#!/bin/bash
set -e
# Set a default port
SSH_PORT=${1:-998}
# Disable password login
sudo sed -i "/PasswordAuthentication/s/yes/no/g" /etc/ssh/sshd_config
# Change port from 22 to ${SSH_PORT}
sudo sed -i "/Port/s/22/${SSH_PORT}/g" /etc/ssh/sshd_config
# Remove hard coded forced port
sudo sed -i "/SSHD_OPTS/s/-p\ 22\ //g" /etc/default/ssh
# Restart sshd
sudo service ssh restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment