Home

Editing sshd_config programmatically

Gunar Gessner

Gunar Gessner

Jan 2, 2021

I've never understood why pubkey authentication is default off. This script disables password authentication and enables pubkey authentication.

#!/usr/bin/env sh
file=/etc/ssh/sshd_config
cp -p $file $file.old &&
awk '
$1=="#PasswordAuthentication" {$1="PasswordAuthentication"; $2="no"}
$1=="#PubkeyAuthentication" {$1="PubkeyAuthentication"; $2="yes"}
{print}
' $file.old > $file


Sign up for the newsletter


Read other stuff