大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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…

问题原文

原帖链接 · Jack Avante · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

  • 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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-02-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。