我如何 运行 systemctl restart apache2 in AWS Ubuntu 当它需要密码时

How do I run systemctl restart apache2 in AWS Ubuntu when it requires a password

我正在尝试重新启动 Apache,但我得到...

ubuntu@ip-172-xx-xx-xx:~$ systemctl restart apache2
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'apache2.service'.
Authenticating as: Ubuntu (ubuntu)

这是一个全新的实例,我从未设置过ubuntu用户密码。创建实例时是否设置了默认密码?

如何在 AWS Ubuntu 中重启 Apache?

如果您在创建实例时设置了密钥对,则用户 ubuntu 没有密码,也不会启用基于密码的登录。您必须使用密钥对登录。

要执行需要提升权限的命令,请在命令前使用 sudo。重新启动 apache2 的实际命令取决于您使用的 Linux 发行版和版本。

sudo systemctl restart apache2

sudo service apache2 restart