From 2a41abbce71411e13e2fe63a5c6ecbe965bd7bfd Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Mon, 23 Sep 2019 13:46:31 +0200 Subject: [PATCH] Add current user to allowed ssh users --- wo/cli/plugins/secure.py | 7 ++++++- wo/cli/templates/sshd.mustache | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wo/cli/plugins/secure.py b/wo/cli/plugins/secure.py index 7016c4d..a0ac649 100644 --- a/wo/cli/plugins/secure.py +++ b/wo/cli/plugins/secure.py @@ -172,7 +172,12 @@ class WOSecureController(CementBaseController): break port = (ssh_line).split(' ') current_ssh_port = (port[1]).strip() - data = dict(sshport=current_ssh_port, allowpass='no') + if os.getenv('SUDO_USER'): + sudo_user = os.environ['SUDO_USER'] + else: + sudo_user = '' + data = dict(sshport=current_ssh_port, allowpass='no', + user=sudo_user) WOTemplate.render(self, '/etc/ssh/sshd_config', 'sshd.mustache', data) WOGit.add(self, ["/etc/ssh"], diff --git a/wo/cli/templates/sshd.mustache b/wo/cli/templates/sshd.mustache index cdd2939..2266ee2 100644 --- a/wo/cli/templates/sshd.mustache +++ b/wo/cli/templates/sshd.mustache @@ -10,7 +10,7 @@ HostKey /etc/ssh/ssh_host_ed25519_key PermitRootLogin without-password # Allow ssh access to some users only -AllowUsers root ubuntu debian +AllowUsers root ubuntu debian {{user}} # allow ssh key Authentication PubkeyAuthentication yes