AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1163124
Accepted
Ani
Ani
Asked: 2024-07-27 03:00:40 +0800 CST2024-07-27 03:00:40 +0800 CST 2024-07-27 03:00:40 +0800 CST

当远程是 WinSCP 时,su -l shell 似乎会自动关闭

  • 772

我有一个在调用时调用的脚本ssh(在 Linux 上)来运行一些命令,然后以其他用户身份登录- 当我使用任何基于 Linux的客户端su -l <anotheruser>时,这一切都运行正常。但是当我尝试使用 WinScp(选项中有文件协议)时,它不起作用!在进一步故障排除时,似乎通过调用的 shell不知何故被杀死了!因此,我在 WinScp 日志中看到以下内容:scpssh SCPsu -l <anotheruser>

(EFatal) **Connection has been unexpectedly closed.** Server sent command exit status 1

但我无法弄清楚为什么仅su在使用 WinScp 时登录 shell 才会被终止!有任何指示可以进一步调试吗?

- 编辑 -

WinSCP 日志的最后几行:

! 2024-07-27 00.23.13.824 su: must be run from a terminal
. 2024-07-27 00.23.13.824 Session sent command exit status 1
. 2024-07-27 00.23.13.824 Main session channel closed
. 2024-07-27 00.23.13.824 All channels closed
. 2024-07-27 00.23.13.824 Timeout waiting for network events
. 2024-07-27 00.23.13.824 Waiting for another 1 bytes
. 2024-07-27 00.23.13.824 Looking for incoming data
. 2024-07-27 00.23.13.824 Looking for network events
. 2024-07-27 00.23.13.824 Attempt to close connection due to fatal exception:
* 2024-07-27 00.23.13.824 **Connection has been unexpectedly closed.** Server sent command exit status 1.
. 2024-07-27 00.23.13.824 Closing connection.
. 2024-07-27 00.23.13.824 Selecting events 0 for socket 1932
* 2024-07-27 00.23.13.856 (EFatal) **Connection has been unexpectedly closed.** Server sent command exit status 1.
* 2024-07-27 00.23.13.856 Error skipping startup message. Your shell is probably incompatible with the application (BASH is recommended).

是否

! 2024-07-27 00.23.13.824 su: must be run from a terminal

指出问题!?

我的脚本通过 NSS 插件调用(libnss-ato)

--编辑2--

在使用su具有--pty选项的 util-linux 版本后,winscp 似乎卡住了!日志:

< 2024-08-02 15.00.55.772 tani1@sys7-vm81B$ echo "WinSCP: this is end-of-file:0"
. 2024-08-02 15.00.55.772 Read 31 bytes (18 pending)
< 2024-08-02 15.00.55.772 WinSCP: this is end-of-file:0
. 2024-08-02 15.00.55.772 Read 18 bytes (0 pending)
. 2024-08-02 15.00.55.772 Waiting for another 1 bytes
. 2024-08-02 15.00.55.772 Looking for incoming data
. 2024-08-02 15.00.55.772 Looking for network events
. 2024-08-02 15.01.12.135 Timeout waiting for network events
. 2024-08-02 15.01.12.135 Waiting for data timed out, asking user what to do.
. 2024-08-02 15.01.12.135 Asking user:
. 2024-08-02 15.01.12.135 **Host is not communicating for 15 seconds.
. 2024-08-02 15.01.12.135 
. 2024-08-02 15.01.12.135 Wait for another 15 seconds?** ()
su
  • 1 1 个回答
  • 69 Views

1 个回答

  • Voted
  1. Best Answer
    Stina Andersson
    2024-08-02T17:59:28+08:002024-08-02T17:59:28+08:00

    su 需要终端才能正常运行,与 WinSCP 一起使用时,无法获得所需的终端环境,从而导致错误。

    相反,使用sudo 代替 su,如果可能的话,考虑使用带有 -i 选项的 sudo 来切换用户。 sudo 不需要像 su 那样的终端。修改脚本以使用 sudo 代替 su 。例如:

    sudo -i -u <anotheruser> <command>
    

    您还可以使用脚本命令创建伪终端。这允许 su 在它认为有终端的环境中运行。如下所示:

    script -q -c "su - <anotheruser> -c '<command>'" /dev/null
    

    在 WinSCP 中,您可以尝试调整设置以确保与终端要求兼容。转到 WinSCP 中的高级设置并调整 Shell 设置。将 shell 设置为 bash 或其他兼容 shell。

    如果上述操作失败,请使用strace进行调试以找出阻碍它的原因。

    • 2

相关问题

  • 如何使用 su 命令访问帐户?

  • 忘记以root / sudo vi打开后保存文件[重复]

  • Linux - 使用“su -”但保留当前目录

  • 设置没有密码的用户

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve