diff options
author | Kelley Spoon <kelley.spoon@linaro.org> | 2023-01-20 07:59:05 -0600 |
---|---|---|
committer | Kelley Spoon <kelley.spoon@linaro.org> | 2023-01-20 07:59:05 -0600 |
commit | 4f8b332ee34def1d67e26848a562c6cfc5ec8a67 (patch) | |
tree | f9e56dfb51a29b492de0badef04a22a41e4ea55c | |
parent | 7526306abb4a9f9c729eafba9626f740b24422b3 (diff) |
ssh_keys: fix a try/except bug
When checking for an existing user authorized_keys file,
the try statement should encapsulate the entire operation
so that if with open() fails (ie, because the user doesn't
have an authorized_keys file yet or the .ssh directory
doesn't exist) it should not be a fatal error.
Change-Id: Iaa015f485afea5494ae9b9c0c40c6644fc2fa706
Signed-off-by: Kelley Spoon <kelley.spoon@linaro.org>
-rwxr-xr-x | ssh_keys.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/ssh_keys.py b/ssh_keys.py index 01cc645..da53354 100755 --- a/ssh_keys.py +++ b/ssh_keys.py @@ -37,11 +37,11 @@ def ldap_sync(): def keys(user): u = pwd.getpwnam(user) if u.pw_uid < 10000: # local user - with open(os.path.join(u.pw_dir, '.ssh/authorized_keys')) as f: - try: + try: + with open(os.path.join(u.pw_dir, '.ssh/authorized_keys')) as f: print(f.read().strip('\n')) - except: - return + except: + return with open('ssh_keys.json') as f: data = json.load(f) |