how to generate an ssh key for another user?

I am trying to clone to a gerrit server using another user username2 however it fails with Permission denied (publickey). ,I tried to generate an ssh key following https://serverfault.com/questions/323958/how-do-you-create-an-ssh-key-for-another-user ,following are the steps I followed which didnt work,what am I missing?

ssh-keygen -f username2
cp ~/.ssh/username2.pub ~/.ssh/authorized_keys
added the username2.pub to  tech-gerrit.sd.company.com

commans I used:

~/.ssh/config:
  Host tech-gerrit
  HostName tech-gerrit.sd.company.com
  Port 29418
  User username2
  IdentityFile /Users/Documents/username2.pub

Trying to clone using below command

git clone ssh://username2@tech-gerrit.sd.company.com:29418

1 answer

  • answered 2018-11-10 07:31 bitinerant

    It would be better to list the exact commands you used so we could also look for typos and know which of the answers in question 323958 you followed. Also, it would be helpful to know about the software and configuration used on company.com.

    However, one thing that stood out as a potential problem: GitHub and GitLab are set up to use git as the username. Perhaps company.com also does this. Try replacing username2 with git in your git clone command.