gpt4 book ai didi

ubuntu - 更改文件权限后无法登录到我的 ubuntu 18.04LTS 服务器

转载 作者:行者123 更新时间:2023-12-04 19:09:31 25 4
gpt4 key购买 nike

我不得不处理从 Google Cloud 的 Ubuntu 服务器上的 PHP 本地服务器执行 bash 命令,在找到解决方案后不久,我与服务器断开连接,现在无法重新登录。

命令我已运行更改目录权限 :sudo chown -R www-data /home/my_username
不用说我搞砸了。
我的网站仍在运行,但 我无法再使用 ssh 登录ssh my_username@server_ip -> 错误:权限被拒绝(公钥)。
或使用谷歌云。

在我从头开始重新启动服务器之前,您有任何线索吗?

最佳答案

根据 Kaybec 分享的 documentation :

The solution is to create a startup script that adds a userid/password pair. If we define this script and then restart our Compute Engine, during the later part of the boot process, the startup script will run which can create our identity which we can then use to login. Once the startup script has completed and the VM instance started, we can then login through the serial port.

Here is walk through of these steps assuming, at the outset, that we are locked out:

  1. We enable serial port login by setting the Compute Engine instance metadata serial-port-enable to 1. In Cloud Console there is a checkbox area which makes this simple:

  2. Next we shutdown the Compute Engine instance.

Once shutdown, we can define our startup script by adding custom metadata with the key of startup-script and the value of:


useradd --groups google_sudoers tempuser
echo "tempuser:password" | chpasswd

您也可以在控制台上执行此操作,在您的 VM 实例的 GCE 页面下,其中显示添加“自定义元数据”

  1. Now we restart the Compute Engine. This will cause the startup script to execute which will add our temporary user. When the Compute Engine has started, we will see a button in the Console of the details of our instance.

We have to press the enter key once in the resulting window to cause the login prompt to appear.

We can now enter our userid and password (eg. tempuser / password). We will be logged in as our temporary user. We can now switch to a root user shell using:


sudo bash

  1. At this point, we are now in the machine with all the authority we may need. We can perform our investigation and repair. When we are happy that the environment has been fixed, we should shutdown the VM instance and remove the startup script that creates our temporary userid and we should also uncheck the box that enables serial port login.


我们应该再次重新启动虚拟机并使用 SSH 登录,并且应该明确删除我们的临时用户:
deluser tempuser

关于ubuntu - 更改文件权限后无法登录到我的 ubuntu 18.04LTS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60477043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com