2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SSH接続でPermission denied (publickey)エラーが表示された時の対処方法:設定ファイルを確認!!

Last updated at Posted at 2023-04-07

このエラーが出たら!!

  • Permission denied (publickey)
  • Authentication failed, permission denied
  • Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

対処方法1 : アクセス許可を修正

鍵のペアが間違っていないのにアクセスできない場合に有効

  • ec2
$ sudo chown root:root /home
$ sudo chmod 755 /home
$ sudo chown ec2-user:ec2-user /home/ec2-user -R
$ sudo chmod 700 /home/ec2-user /home/ec2-user/.ssh
$ sudo chmod 600 /home/ec2-user/.ssh/authorized_keys
  • ec2以外
$ sudo chown root:root /home
$ sudo chmod 755 /home
$ sudo chown {ユーザー名}:{ユーザー名} /home/{ユーザー名} -R
$ sudo chmod 700 /home/{ユーザー名} /home/{ユーザー名}/.ssh
$ sudo chmod 600 /home/{ユーザー名}/.ssh/authorized_keys

対処方法2 : クライアント側の鍵のアクセス許可を修正

$ sudo chmod 400 ~/.ssh/{ペアとなる鍵}

対処方法3 : known_hostsファイル削除

$ cd ~/.ssh && rm -Rf known_hosts && known_hosts.old
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?