AWS:如何切换为“root”用户?

Har*_*ram 2 root rhel-6 redhat-enterprise-linux

我在 aws 中新建了 EC2 实例,并且能够使用私钥以 EC2 用户身份登录,但想以 root 身份登录以安装软件包。无法以 root 身份切换尝试 sudo - 但它要求输入密码,我还没有为 root 创建任何密码。我被困在这里

小智 5

对于 Amazon Linux 2,您可以使用 sudo su

[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo su

[root@ip-xxx-xxx-xxx-xxx ec2-user]# whoami
root
Run Code Online (Sandbox Code Playgroud)