无法ssh到远程服务器

Unable to ssh to remote server

我正在尝试通过 ssh 登录到我的 lightsail 帐户上的特定用户,但我收到权限被拒绝(public 密钥)错误

这是我遵循的步骤(我在 git bash 在 windows 8)

  1. 通过 aws

    提供的 .pem 密钥通过 ssh 进入我的 lightsail 帐户

    ssh -i <key.pem> ubuntu@<public_ip_address>

(我现在已登录到我的 lightsail 服务器)

  1. sudo adduser user1
  2. sudo touch /etc/sudoers.d/user1
  3. sudo nano /etc/sudoers.d/user1

** 用户 1 ALL=(ALL:ALL) ALL**

  1. su - user1

  2. sudo mkdir .ssh

  3. sudo touch .ssh/authorized_keys

我打开另一个 shell 提示并执行以下操作

-ssh-keygen

-cat <file_location_of_key>.pub

-复制内容

  1. 粘贴在我的本地机器上创建的 public 密钥的内容 通过 ssh-keygen
  2. sudo chmod 700 .ssh
  3. sudo chmod 600 .ssh/authorized_keys
  4. sudo 服务 ssh 重启
  5. 退出

我退出 lightsail 帐户并尝试通过 ssh 连接到评分者用户

ssh -i <file_location_of_key> user1@<public_ip_address>

我收到错误 Permission denied (publickey).

注意:我还没有更改任何端口设置。我仍在尝试将它连接到我的默认端口 22

@RickBaker @helloV 感谢您的帮助。意识到该文件仍归 root 所有。必须将文件的所有权更改为 user1。 ssh 现在工作正常