由于 /etc/profile.d 中的脚本以退出状态 1 退出,因此无法使用 SSH 登录服务器

sti*_*ibi 4 shell bash ssh

所以我遇到了这个问题,我无法使用 SSH 登录到我的服务器。\n请参阅:

\n\n
ssh -v myuser@myserver\ndebug1: Authentication succeeded (password).\ndebug1: channel 0: new [client-session]\ndebug1: Requesting no-more-sessions@openssh.com\ndebug1: Entering interactive session.\ndebug1: Sending environment.\ndebug1: Sending env LANG = en_US.UTF-8\nLast login: Sun Jul  5 20:10:54 2015 from x.x.x.x\n-bash: KSH_VERSION: unbound variable\ndebug1: client_input_channel_req: channel 0 rtype exit-status reply 0\ndebug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0\ndebug1: channel 0: free: client-session, nchannels 1\nConnection to x.x.x.x closed.\nTransferred: sent 2264, received 2800 bytes, in 0.2 seconds\nBytes per second: sent 13241.8, received 16376.8\ndebug1: Exit status 1\n
Run Code Online (Sandbox Code Playgroud)\n\n

问题是“-bash:KSH_VERSION:未绑定变量”,我认为这会终止连接。\n我知道为什么会发生\xe2\x80\xa6我正在处理放置在/etc/profile.d中的脚本,并且这个脚本中有“set -euo pipelinefail”(哎哟)...\n“o”选项是“nounset”,它解释了“未绑定变量”...\n当脚本设置选项时,它使 vim. sh 在未绑定变量上失败。

\n\n

现在,如何解决这个问题?我无法通过 ssh 发送命令来删除文件,例如,我无法以另一个用户身份登录,我无法使用另一个 shell,即“--noprofile”和“--norc” " bash 选项不起作用\xe2\x80\xa6我尝试过的技巧没有起作用\xe2\x80\xa6

\n\n

有什么想法吗?

\n

小智 5

我遇到了同样的问题,终于找到了解决方案。

正如@nkms 提到的:

在获取 /etc/profile 之前,您有大约 1/3 的机会(至少我有 1/3)中断(按 Ctrl+C)登录过程

为了增加你的机会,我使用了以下循环:

$ (trap '' INT; while true; do ssh myuser@myserver; done)
Run Code Online (Sandbox Code Playgroud)

该脚本启动 subshel​​l '(' 并停用该子 shell 的 ctr-c 命令(使用 trap 命令)。然后它循环执行 ssh 命令。如果您连续按 ctrl-c 或按住 ctrl-c,则会增加机会抓住正确的时机。

... 奇迹般有效!