Skip to content

Commit

Permalink
Create authorized_keys with correct owner
Browse files Browse the repository at this point in the history
Previously `~pi/.ssh/authorized_keys` was created with the current user (root) as owner. This causes `ssh-copy-id` to fail when the user tries to upload their ssh key to the host. Now it should have the correct permissions.
  • Loading branch information
rotu authored Sep 21, 2023
1 parent eea05f5 commit 4ec4f91
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/services/commander/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def setup_ssh() -> None:
subprocess.run(shlex.split(f"ssh-keygen -t rsa -f {key_path}/id_rsa -q -N ''"), check=True)
# add id_rsa.pub to authorized_keys if not there already
if not os.path.exists(authorized_keys_path):
subprocess.run(shlex.split(f"touch {authorized_keys_path}"), check=True)
shutil.touch(authorized_keys_path, mode=0o600)
shutil.chown(authorized_keys_path, 'pi', 'pi')
with open(authorized_keys_path, "r+", encoding="utf-8") as f:
with open(key_path_as_path / "id_rsa.pub", encoding="utf-8") as key_file:
my_key = key_file.read()
Expand Down

0 comments on commit 4ec4f91

Please sign in to comment.