简体   繁体   English

无法SSH到远程服务器

[英]Unable to ssh to remote server

I'm trying to log in to a particular user on my lightsail account via ssh but I get a permission denied (public key) error 我正在尝试通过ssh登录到我的lightail帐户中的特定用户,但我收到一个权限被拒绝(公钥)错误

Here are the steps I followed(I am on git bash on windows 8) 这是我遵循的步骤(我在Windows 8上是git bash)

  1. ssh into my lightsail account via the .pem key provided via aws 通过aws提供的.pem密钥ssh进入我的lightail帐户

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

(I am now logged in to my lightsail server) (我现在已经登录到我的lightail服务器)

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

** user1 ALL=(ALL:ALL) ALL** ** user1 ALL =(全部:全部)全部**

  1. su - user1

  2. sudo mkdir .ssh

  3. sudo touch .ssh/authorized_keys

I open Another shell prompt and do the following 我打开另一个shell提示,然后执行以下操作

- ssh-keygen ssh-keygen

- cat <file_location_of_key>.pub - cat <file_location_of_key>.pub

-copy the contents -复制内容

  1. paste the contents of the public key created on my local machine via ssh-keygen 通过ssh-keygen粘贴在本地计算机上创建的公共密钥的内容
  2. sudo chmod 700 .ssh 须藤chmod 700 .ssh
  3. sudo chmod 600 .ssh/authorized_keys 须藤chmod 600 .ssh / authorized_keys
  4. sudo service ssh restart sudo服务ssh重新启动
  5. exit 出口

I exit from the lightsail account and try to ssh to the grader user 我退出了lightail帐户,并尝试通过SSH转到平地机用户

ssh -i <file_location_of_key> user1@<public_ip_address>

I get the error Permission denied (publickey). 我收到错误权限被拒绝(公钥)。

Note: I havn't changed any port setting yet. 注意:我尚未更改任何端口设置。 I'm still trying to connect it to my default port 22 我仍在尝试将其连接到默认端口22

@RickBaker @helloV Thanks for your help. @RickBaker @helloV感谢您的帮助。 Realised the file was still owned by root. 意识到该文件仍由root拥有。 Had to change to ownership of the file to user1. 不得不将文件的所有权更改为user1。 ssh works fine now SSH现在可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM