简体   繁体   中英

I am able to ssh to remote server only if i am sudo

I researched and found that to change mod of.ssh to 700 so

[ec2-user@ip-114 .ssh]$ sudo cp /root/.ssh/id_rsa /home/ec2-user/.ssh/id_rsa
[ec2-user@ip-114 .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[ec2-user@ip-114 .ssh]$ pwd
/home/ec2-user/.ssh
[ec2-user@ip-114 ~]$ cd ..

[ec2-user@ip-114 ~]$ chmod 700 .ssh/
[ec2-user@ip-114 ~]$ cd .ssh/
[ec2-user@ip-114 .ssh]$ ssh -i "id_rsa.pub" ubuntu@x.x.x.x
Load key "id_rsa.pub": Permission denied
Permission denied (publickey).
[ec2-user@ip-114 .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts

Even after change mod it saying permision denied.

If i do

sudo su
[ec2-user@ip-114 .ssh]$ sudo su
[root@ip-172-114 .ssh]# ssh  ubuntu@x.x.x.x
Enter passphrase for key '/root/.ssh/id_rsa': 

Which is target behaviour for non root user.
Whats going wrong?

You are trying to connect via the public key, you should be connecting via id_rsa .

Additionally please make sure it has permissions 400 with your user as the owner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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