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

SSH to droplet with non root user

· 52CE 我爱测

I recently made some new users in my digitalocean droplet, and I would like to access them directly with the command ssh username@ip . However, I get denied with username@ip: Permission denied (publickey) . For clarification, the…

问题原文

原帖链接 · Jonas Grønbek · CC BY-SA 4.0

I recently made some new users in my digitalocean droplet, and I would like to access them directly with the command ssh username@ip. However, I get denied with username@ip: Permission denied (publickey). For clarification, the machine has the correct private-key and can access the droplet with ssh root@ip

I did the following to create the new user

root@school:~# adduser username
Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

After these steps, what is further to do to be able to access the droplet with ssh username@ip ?

已采纳解答

原帖链接 · HBruijn · CC BY-SA 4.0

"the machine has the correct private-key"

That is the root cause of your misunderstanding. Access is controlled separately for each account, not for the machine as a whole.

For each account you want to access with a particular key you will need to append the associated public key to the file ~/.ssh/authorized_keys in the home directory of that account.

Or in other words: copy /root/.ssh/authorized_keys to /home/username/.ssh/authorized_keys and ensure the correct ownership and permissions on those files/directories.

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

资料来源与适用范围

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

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

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