1

I have local user usr1 and root user in my mac. I can ssh using following command as a root user to a remote server but can't ssh using usr1.

ssh -i .ssh/pem1.pem ubuntu@server1

I know since the permission for pem1.pem is 600 so only root has access to it and can access it but if I have to ssh to the remote server via usr1 and if I change the permission to 666 or 777 then it gives me the permission is not corrrect for the pem file. Is there any way to get around this situation?

2
  • 3
    Each account needs its own identity file, readable only by that account. If two accounts were able to use the same identity file, it would no longer be "secure" shell. I'll let someone else write the full answer because it needs more details than I can provide.
    – WGroleau
    Aug 30, 2022 at 0:25
  • 1
    This site works better with only one question per, well, question. I've edited out the second one, feel free to ask it as a separate question.
    – nohillside
    Aug 30, 2022 at 12:51

1 Answer 1

1

Each user needs to have a copy of pem1.pem in their respective ~/.ssh directory, set to 0600 and owned by them.

So, assuming you are logged in as root, run

mkdir -p ~usr1/.ssh
cp ~/.ssh/pem1.pem ~usr1/.ssh/
chmod 600 ~usr1/.ssh/pem1.pem
chown usr1:staff ~usr1/.ssh/pem1.pem ~usr1/.ssh
chmod 700 ~usr1/.ssh

Depending on the target system you are logging into it may be more useful (and secure) to use different credentials for each user.

1
  • 2
    my problem was that I was chaning the permission recursively at once for .ssh folder so either I can't access the folder as local user or if local user has access then the .ssh folder did not have 700 permission. THank you for the elaborated answer
    – 10raw
    Aug 30, 2022 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .