简体   繁体   English

是否可以使用PEM文件以root用户身份连接到ec2实例?

[英]Is it possible to connect to ec2 instance as root user by using the PEM file?

I'm trying to connect to an EC2 AWS instance but when I tried to install PHPMYADMIN the linux console asks me for the root user password, which I forgot about. 我正在尝试连接到EC2 AWS实例,但是当我尝试安装PHPMYADMIN时,Linux控制台要求我提供我忘记的root用户密码。 Could anyone please know how to use .PEM file to login as the root user? 有人可以知道如何使用.PEM文件作为root用户登录吗? I tried sudo su command but it still asks me for the root user. 我尝试了sudo su命令,但仍然要求我提供root用户。 Any help is appreciated. 任何帮助表示赞赏。

Disclaimer: It is not recommended to login as root. 免责声明: 不建议以root用户身份登录。

But still if you want to, then: 但是,如果您仍然愿意,则:

  1. Allow PermitRootLogin in /etc/ssh/sshd_config /etc/ssh/sshd_config允许PermitRootLogin
  2. Restart SSH service 重新启动SSH服务
  3. you need to paste the existing public key which is in the /home/ec2-user/.ssh/authorized_keys to /root/.ssh/authorized_keys 您需要将/home/ec2-user/.ssh/authorized_keys的现有公钥粘贴到/root/.ssh/authorized_keys

Now you should be able to login as root using the .pem key. 现在,您应该可以使用.pem密钥以root用户身份登录。

You don't need your root password if you are running sudo su - , you need the password of the user you are running the sudo command as. 如果您正在运行sudo su - ,则不需要root密码,而您正在运行sudo su -的用户则需要密码。 Provided that the user has sudo privileges as root. 前提是该用户具有root用户的sudo特权。 Then you can just run as root: 然后,您可以以root身份运行:

yum install phpmyadmin

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

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