ssh: Option for disabling password authentication

Closes: #572

[sunil: Reload instead of restart, fix i18n strings]
[sunil: Load augeas minimally, minor cosmetic fixes]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Nektarios Katakis authored and Sunil Mohan Adapa committed 2019-10-29 14:50:46 -07:00
1 parent caa336babc
commit ddb95752a8
4 files changed
+117 -1

No files matched your search

+36 -1
View File
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Configuration helper for SSH server.
"""
@@ -28,6 +27,8 @@ import stat
import subprocess
import sys
import augeas
from plinth import action_utils
@@ -47,6 +48,13 @@ def parse_arguments():
set_keys.add_argument('--username')
set_keys.add_argument('--keys')
subparsers.add_parser('get-password-config',
help='Get SSH password auth configuration')
set_password_config = subparsers.add_parser(
'set-password-config', help='Set SSH password auth configuration')
set_password_config.add_argument('--value')
subparsers.required = True
return parser.parse_args()
@@ -107,6 +115,33 @@ def subcommand_set_keys(arguments):
os.chmod(key_file_path, stat.S_IRUSR | stat.S_IWUSR)
def _load_augeas():
"""Initialize augeas for this app's configuration file."""
aug = augeas.Augeas(
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
aug.set('/augeas/load/Sshd/lens', 'Sshd.lns')
aug.set('/augeas/load/Sshd/incl[last() + 1]', '/etc/ssh/sshd_config')
aug.load()
return aug
def subcommand_get_password_config(_):
"""Retrieve value of password authentication from sshd configuration."""
aug = _load_augeas()
field_path = '/files/etc/ssh/sshd_config/PasswordAuthentication'
get_value = aug.get(field_path)
print(get_value or 'yes')
def subcommand_set_password_config(arguments):
"""Set value of password authentication in sshd configuration."""
aug = _load_augeas()
aug.set('/files/etc/ssh/sshd_config/PasswordAuthentication',
arguments.value)
aug.save()
def main():
"""Parse arguments and perform all duties."""
arguments = parse_arguments()