Score:1

Adding my SSH key to new user with only SSH access through key

in flag

I'm quite new to this, and I've looked through questions but haven't found one that quite matches my problem, or rather I didn't sufficiently understand them to be able to solve this issue.

I have a new server to which I can only access using a pre-generated SSH RSA key pair, which allows me to connect only to the default ubuntu user

ssh -i .ssh/mykey ubuntu@ipaddr

On the server I created a new user, newuser, and I'm trying to make it, so I can use my key that I connect to ubuntu on that account as well, but I'm not sure how to accomplish this, so I can then delete the ubuntu user.

ssh-copy-id -i .ssh/mykey.pub -o "IdentityFile .ssh/mykey" newuser@ipaddr

That though returns permission denied. How can I do this effectively? Any password login is disabled and can't be enabled in this instance.

Score:1
in flag
  • ssh to your old user ubuntu
  • use sudo -i -u newuser to switch to the new user
  • open ~newuser/.ssh/authorized_keys with your favourite editor and copy&paste the content of your new public key into it
  • set proper permissions on the .ssh directory and the files inside it.

you may need to create the directory ~newuser/.ssh if it doesn't exist yet

in flag
Don't forget to give sudo access to your new user before you delete the old one.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.