AWS:如何切換為「root」使用者?

AWS:如何切換為「root」使用者?

我在 aws 中新建了 EC2 實例,並且能夠使用私鑰以 EC2 使用者身分登錄,但想以 root 身分登入來安裝軟體包。無法切換,因為 root 嘗試了 sudo - 但它要求輸入密碼,我還沒有為 root 創建任何密碼。我被困在這裡了

答案1

對於 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

答案2

現在可以使用了,需要透過輸入「passwd」指令為 root 建立密碼並為 root 設定密碼。切換使用者“su root”命令。

相關內容