本月无法登录或 ssh 到非管理员 Cygwin 用户,但上个月可以登录或 ssh 到其他非管理员用户

本月无法登录或 ssh 到非管理员 Cygwin 用户,但上个月可以登录或 ssh 到其他非管理员用户

我读过几乎所有关于这个问题的变体的谷歌链接,但它们似乎都不适用,这让我感到困惑。

除了我的许多 Linux 计算机之外,我还有一台安装了 Cygwin 的 Windows 10 笔记本电脑,通过其安装文件完全更新了 Windows 更新和 Cygwin 更新。它有一个管理员用户(严格用于维护)和两个分配给用户组(且不属于其他组的成员)的非管理员用户帐户,用于日常操作。所有三个帐户多年来都完美运行,Cygwin 能够启动各自的 cygwin 终端和/或通过 SSH 登录到本地主机。本月,由于某种未知原因,User1 帐户无法启动 Cygwin 终端。相反,它总是提示输入管理密码。如果选择“否”,Cygwin 终端将永远不会打开。如果您单击“是”并提供管理员密码,您实际上并没有以 User1 身份登录,这是一个问题,因为 User1 不需要是管理员,并且需要访问自己的 git 文件、存储库等来推送/拉取其更新。

如果管理员运行“ssh User1@localhost”,它会通过密码验证,但随后立即被踢出,并出现以下类型的消息:


Last login: Sat Apr  1 21:57:31 2017 from ::1
Connection to localhost closed.

请注意,上次登录确认登录成功,但总是会立即退出。使用 User2 运行相同的命令没有问题,确认 sshd 工作正常。

通过管理员帐户从 cygwin 终端运行“login User1”会导致提示输入 User1 的密码,成功输入后,再次被踢出并显示以下消息:


Password:
Switching to user User1 failed!

User2 做这些事情绝对没有问题。请记住,User1 过去能够在上个月和过去几年中完成所有这些操作。

我重新安装了 sshd (甚至通过 Cygwin 安装文件升级了它)并重新运行 ssh-host-config 但似乎没有任何帮助。 (ssh 适用于 Admin 和 User2。)这是我已经检查过的内容。

  • User1 不在 /etc 中的任何黑名单中。我通过检查报告的文件进行了确认

 find /etc -type f -exec grep -il User1 {} \;
  • 我已经多次重新创建了 passwd 和组文件。

mkpasswd -l > /etc/passwd
mkgroup -l > /etc/group
  • User1 的 shell 是 /bin/bash (而不是 /bin/false 或任何变体)

User1:*:197609:197121:U-Jack-VAIO\User1,S-1-5-21-2974605114-333831212-2175464639-1001:/home/User1:/bin/bash
User2:*:197610:197121:U-Jack-VAIO\User2,S-1-5-21-2974605114-333831212-2175464639-1002:/home/User2:/bin/bash
  • User1 可以正常登录 Windows。 (compmgmt.msc > 用户中未禁用,密码也未过期。)

  • 我已经删除了 /etc/passwd 和 /etc/group 因为它们是当前 Cygwin 中不再需要

  • 我已在“本地用户和组”中确认 User1 的描述为空(这是可以接受的,并且是当 /etc/passwd 不存在时 Cygwin 查找 /etc/passwd 字段的替代位置)。

  • “Cygwin Terminal.lnk”快捷方式与 User2 使用的快捷方式完全相同,没有任何问题。它位于 /cygdrive/c/Users/Public/Desktop 中。 (它没有选中“以管理员身份运行”复选框。但是,系统会提示 User1 输入管理员密码。)

  • User1 的 .bashrc 或 .bash_profile 中没有任何内容可以使其退出。 (参见下一个项目符号。)

  • User1 的 /home/User1 权限与 User2 的相同。事实上,我什至尝试将 /home/User1 移动到另一个名称,创建一个新的 /home/User1 ,其中什么都没有(相同的结果),然后复制 /etc/skel 并将权限更改为 chown -R User1 :无(相同结果)。


drwxr-xr-x+ 1 Admin   None 0 Apr  1 22:07 Admin
drwxr-xr-x+ 1 User1    None 0 Apr  1 21:52 User1
drwxr-xr-x+ 1 User1    None 0 Apr  1 21:56 User1.001
drwxr-xr-x+ 1 User1    None 0 Apr  1 18:05 User1.old
drwxr-xr-x+ 1 User2    None 0 Oct 21 09:36 User2

drwxr-xr-x+ 1 User1  None    0 Apr  1 21:52 .
drwxrwxrwt+ 1 Admin None    0 Apr  2 06:48 ..
-rw-r--r--  1 User1  None 1494 Jan 16 15:07 .bash_profile
-rw-r--r--  1 User1  None 6054 Jan 16 15:07 .bashrc
-rw-r--r--  1 User1  None 1919 Jan 16 15:07 .inputrc
-rw-r--r--  1 User1  None 1236 Jan 16 15:07 .profile
  • 我可以在 compmgmt.msc > 用户和组中创建一个新的非管理员 User3,设置密码,然后像 User2 一样成功 ssh 进入它。 Cygwin 从 /etc/skel.conf 自动创建 User3 的 home。如果我删除 User1 的 /home/User1 目录,则通过 SSH 登录时不会自动重新创建该目录,当然,我会被踢回管理员 shell。

这是 ssh -vvv User1@localhost 与 User2 的样子。我只包含了验证成功后的部分,以便您可以看到差异。


用户1:


debug1: Next authentication method: password
User1@localhost's password:
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (password).
Authenticated to localhost ([::1]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 91
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IPV6_TCLASS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Last login: Sun Apr  2 06:43:18 2017 from ::1
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

debug3: send packet: type 1
Connection to localhost closed.
Transferred: sent 2248, received 2868 bytes, in 0.1 seconds
Bytes per second: sent 15979.1, received 20386.1
debug1: Exit status 255

Admin@Jack-VAIO ~
$


用户2:


debug1: Next authentication method: password
User2@localhost's password:
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
debug1: Authentication succeeded (password).
Authenticated to localhost ([::1]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 91
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IPV6_TCLASS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Last login: Sat Apr  1 20:56:04 2017 from ::1

User2@Jack-VAIO ~
$
  • 更新:在启用日志记录的最新重新安装的 SSHD 中,当我尝试以 User1 身份进行 ssh 时,我看到了以下特定消息:

setreuid 197609: Operation not permitted
setresuid 197609: Operation not permitted

所以你有它。我完全困惑了。需要注意的一件事是,从 Windows 中删除 User1 并重新创建不是一个选项,因为我已经设置了多年的配置设置,并且不会重新创建,特别是当 User1 和 User2 的其他一切都正常工作时。 User1 无法再访问自己的 Cygwin 帐户。

关于还有什么要检查的任何想法,因为我刚刚摆脱它们。

PS 感谢您阅读本文。

答案1

经过进一步研究(这里这里)我倾向于认为问题不在于 Cygwin,而在于 Windows 10。昨天,当我使用 User2 的 Windows 帐户并注意到我可以在没有 UAC 提示的情况下启动任务管理器时,我的脑海中突然灵光一闪——我知道 User1 总是被提示从 Windows 8 升级到 Windows 10(尽管该升级是在大约一年前免费升级到 Win 10 促销期间进行的)。我认为这是 Windows 10 的事情,并且没有多想。当我意识到 User2 发生这种情况时,并在 google 上搜索解决方法来修复 User1 的问题,我发现我可以对 User1 的 Cygwin 问题使用相同的解决方法。它仍然没有回答 User1 的帐户最初是如何混乱的,也没有回答如何以正确的方式实际修复它,但我对这个解决方法感到满意,因为我现在可以为 User1 完成 git 更改。

长话短说

解决方法:

  • 打开命令行(CMD.EXE)并设置此变量以停止获取UAC弹出提示:

set __compat_layer=runasinvoker
  • 从同一终端设置环境变量,启动 Cygwin:

c:\cygwin64\bin\mintty.exe
  • 使该用户永久生效(并使桌面图标再次工作)

setx __compat_layer "runasinvoker"
  • 要使该设置对计算机范围内的所有用户永久有效,请打开管理命令行,然后:

setx /m __compat_layer "runasinvoker"
  • 最后,要在不修复 Cygwin 的情况下访问 git,请安装“Git Bash”。

警告:由于 User1 帐户在技术上仍然损坏,我仍然无法使用 ssh 登录,但我至少可以以 User1 身份访问本地 Cygwin 终端。此外,此解决方法无法修复通过 sysdm.cpl GUI 修改 User1 的 Windows 用户环境变量的能力(仍然获得 UAC 提示,然后仅显示管理员的 ENV 变量而不是 User1 的),但这现在是 Windows 相关的 Stack Exchange 论坛的内容我知道这是 Windows 帐户问题,而不是 Cygwin 的问题。 SETX 允许从命令行更改用户和机器 ENV 变量。

相关内容