在几个月没有碰过它之后,我想登录我们的一台虚拟服务器来更新 OpenSSL,因为心血的事情。服务器运行的是Debian 7,sudo
未安装。
我尝试了三种方法:
ssh root@server
,密码被接受,然后:Could not chdir to home directory /home/root: No such file or directory Connection to server closed.
以其他用户身份登录,然后
su - root
。No directory, logging in with HOME=/
然后我回到了通常的 shell,不再以 root 身份登录。
以其他用户身份登录,然后
su root
。这没有给出任何结果,我只是回到了通常的提示,仍然以其他用户而不是 root 身份登录。
我没有机会在周一之前手动重新启动服务器。我可以尝试做些什么来获得root shell吗?服务器可能受到威胁,我该如何检查(没有 root 访问权限)?谢谢你!
在所有情况下,当输入错误的密码时,机器会像往常一样抱怨。
/root
确实存在并/etc/passwd
列出正确的目录。我不知道为什么 ssh 的看法不同。
这可能很重要:在调用$?
失败后进行检查su
会给出一个1
,这是System or authentication failure
根据 su 的手册页。我怎样才能让它更详细?
按照下面的要求,输出ssh -v
:
Last login: Fri Apr 11 17:47:46 2014 from some_client
Could not chdir to home directory /home/root: No such file or directory
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to server closed.
Transferred: sent 3136, received 2448 bytes, in 0.0 seconds
Bytes per second: sent 299688.7, received 233940.7
debug1: Exit status 1
答案1
以下内容全部来自 这里。
该错误消息表明根目录的主目录丢失。您可以使用 重新创建它mkdir /root
,但它会是空的。
通常,您不应直接以 root 身份登录。对于远程登录和 X 会话,应禁用所有直接 root 访问,尽管在出现问题时允许从文本模式终端进行 root 访问可能会成为救星。您应该始终以真实用户身份登录,然后使用su
或su -
(当然还有 root 密码)更改为 root 用户。
但是,在您的情况下, su 无效,因为您仍然没有该/root
目录。
创建/root目录后,您仍然会缺少一些默认文件。
您需要的文件是默认文件.bash_profile
,.bashrc
应将这些文件复制到/root
.前导.
意味着文件是隐藏的,因此您可能需要做ls -a
才能看到它们。
编辑
实际问题是,对于 root 用户,shell 设置为/bin/false
.这可以通过发出命令来验证,
getent passwd root
在这种情况下,上述命令的输出结果是,
root:x:0:0:Netbios Domain Administrator:/home/root:/bin/false
如果您有sudo
用户,则可以更改它,或者您应该在模式下启动机器single
并编辑上述设置。