我的 WinSCP 配置:
File protocol: SCP
user name: namjoo
port: 22
settings > SCP/Shell > Shell: sudo su -
当我尝试连接时出现此错误:
跳过启动消息时出错。您的 shell 可能与应用程序不兼容(建议使用 BASH)。
我的日志文件是:
root@hostname:~# systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-05-14 17:21:37 UTC; 1h 36min ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 2519 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 2532 (sshd)
Tasks: 1 (limit: 19062)
Memory: 3.1M
CGroup: /system.slice/ssh.service
└─2532 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
May 14 18:17:25 hostname sshd[2905]: pam_unix(sshd:session): session closed for user my_username
May 14 18:18:00 hostname sshd[2995]: Accepted password for my_username from 192.168.1.151 port 60242 ssh2
May 14 18:18:00 hostname sshd[2995]: pam_unix(sshd:session): session opened for user my_username by (uid=0)
May 14 18:18:01 hostname sshd[2995]: pam_unix(sshd:session): session closed for user my_username
May 14 18:20:40 hostname sshd[3112]: Accepted password for my_username from 192.168.1.151 port 60495 ssh2
May 14 18:20:40 hostname sshd[3112]: pam_unix(sshd:session): session opened for user my_username by (uid=0)
May 14 18:20:41 hostname sshd[3112]: pam_unix(sshd:session): session closed for user my_username
May 14 18:58:16 hostname sshd[3233]: Accepted password for my_username from 192.168.1.151 port 64655 ssh2
May 14 18:58:16 hostname sshd[3233]: pam_unix(sshd:session): session opened for user my_username by (uid=0)
May 14 18:58:17 hostname sshd[3233]: pam_unix(sshd:session): session closed for user my_username
我的用户是my_username
。我最近安装了它。WinSCP 日志文件的内容:
. 2022-05-15 19:57:10.067 --------------------------------------------------------------------------
. 2022-05-15 19:57:10.067 WinSCP Version 5.17.10 (Build 11087) (OS 10.0.19043 - Windows 10 Enterprise)
. 2022-05-15 19:57:10.067 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2022-05-15 19:57:10.067 Log level: Normal
. 2022-05-15 19:57:10.067 Local account: WIN\namjoo
. 2022-05-15 19:57:10.067 Working directory: C:\Program Files (x86)\WinSCP
. 2022-05-15 19:57:10.067 Process ID: 5692
. 2022-05-15 19:57:10.067 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe"
. 2022-05-15 19:57:10.067 Time zone: Current: GMT+4:30, Standard: GMT+3:30 (Iran Standard Time), DST: GMT+4:30 (Iran Daylight Time), DST Start: 3/22/2022, DST End: 9/21/2022
. 2022-05-15 19:57:10.067 Login time: Sunday, May 15, 2022 7:57:10 PM
. 2022-05-15 19:57:10.067 --------------------------------------------------------------------------
. 2022-05-15 19:57:10.067 Session name: [email protected] (Site)
. 2022-05-15 19:57:10.067 Host name: 192.168.1.150 (Port: 22)
. 2022-05-15 19:57:10.067 User name: namjoo (Password: No, Key file: No, Passphrase: No)
. 2022-05-15 19:57:10.067 Tunnel: No
. 2022-05-15 19:57:10.067 Transfer Protocol: SCP
. 2022-05-15 19:57:10.067 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2022-05-15 19:57:10.067 Disable Nagle: No
. 2022-05-15 19:57:10.067 Proxy: None
. 2022-05-15 19:57:10.067 Send buffer: 262144
. 2022-05-15 19:57:10.067 SSH protocol version: 2; Compression: No
. 2022-05-15 19:57:10.067 Bypass authentication: No
. 2022-05-15 19:57:10.067 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2022-05-15 19:57:10.067 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2022-05-15 19:57:10.067 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2022-05-15 19:57:10.067 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2022-05-15 19:57:10.067 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2022-05-15 19:57:10.067 Simple channel: Yes
. 2022-05-15 19:57:10.067 Return code variable: Autodetect; Lookup user groups: Auto
. 2022-05-15 19:57:10.067 Shell: sudo su -
. 2022-05-15 19:57:10.067 EOL: LF, UTF: Auto
. 2022-05-15 19:57:10.067 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2022-05-15 19:57:10.067 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2022-05-15 19:57:10.067 Local directory: default, Remote directory: /var/www/lichens, Update: Yes, Cache: Yes
. 2022-05-15 19:57:10.067 Cache directory changes: Yes, Permanent: Yes
. 2022-05-15 19:57:10.067 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2022-05-15 19:57:10.067 DST mode: Unix;Timezone offset: 0h 0m
. 2022-05-15 19:57:10.067 --------------------------------------------------------------------------
. 2022-05-15 19:57:10.120 Looking up host "192.168.1.150" for SSH connection
. 2022-05-15 19:57:10.120 Connecting to 192.168.1.150 port 22
. 2022-05-15 19:57:10.136 We claim version: SSH-2.0-WinSCP_release_5.17.10
. 2022-05-15 19:57:10.136 Remote version: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
. 2022-05-15 19:57:10.136 Using SSH protocol version 2
. 2022-05-15 19:57:10.136 Have a known host key of type ssh-ed25519
. 2022-05-15 19:57:10.152 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2022-05-15 19:57:10.276 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2022-05-15 19:57:10.276 Host key fingerprint is:
. 2022-05-15 19:57:10.276 ssh-ed25519 255 65:d6:2c:01:60:77:9b:bc:e3:71:b0:92:00:ee:32:88 obPgbW2b75UCCFNcIELRozzTRqFSbLNRNOccK63VtTE=
. 2022-05-15 19:57:10.338 Host key matches cached key
. 2022-05-15 19:57:10.338 Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
. 2022-05-15 19:57:10.338 Initialised HMAC-SHA-256 outbound MAC algorithm
. 2022-05-15 19:57:10.338 Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
. 2022-05-15 19:57:10.338 Initialised HMAC-SHA-256 inbound MAC algorithm
! 2022-05-15 19:57:10.338 Using username "namjoo".
. 2022-05-15 19:57:10.369 Server offered these authentication methods: publickey,password
. 2022-05-15 19:57:10.369 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2022-05-15 19:57:14.784 Sent password
. 2022-05-15 19:57:14.810 Access granted
. 2022-05-15 19:57:14.810 Opening main session channel
. 2022-05-15 19:57:15.576 Opened main channel
. 2022-05-15 19:57:15.576 Started a shell/command
. 2022-05-15 19:57:15.607 --------------------------------------------------------------------------
. 2022-05-15 19:57:15.607 Using SCP protocol.
. 2022-05-15 19:57:15.607 Doing startup conversation with host.
. 2022-05-15 19:57:15.623 Skipping host startup message (if any).
> 2022-05-15 19:57:15.623 echo "WinSCP: this is end-of-file:0"
! 2022-05-15 19:57:15.623 sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
. 2022-05-15 19:57:15.623 Session sent command exit status 1
. 2022-05-15 19:57:15.623 Main session channel closed
. 2022-05-15 19:57:15.623 All channels closed
. 2022-05-15 19:57:15.623 Attempt to close connection due to fatal exception:
* 2022-05-15 19:57:15.623 **Connection has been unexpectedly closed.** Server sent command exit status 1.
. 2022-05-15 19:57:15.623 Closing connection.
* 2022-05-15 19:57:15.652 (EFatal) **Connection has been unexpectedly closed.** Server sent command exit status 1.
* 2022-05-15 19:57:15.652 Error skipping startup message. Your shell is probably incompatible with the application (BASH is recommended).
cat /etc/sudoers
:
root ALL=(ALL:ALL) ALL
darwin ALL=NOPASSWD:ALL
namjoo ALL=NOPASSWD:ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
答案1
从日志文件中:
! 2022-05-15 19:57:15.623 sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
首先,将 shell 重置为其默认值并确认其有效。
然后考虑一下您要复制的文件:您真的需要 root 访问权限吗?如果是,我强烈建议您为 root 帐户设置公钥/私钥,然后直接登录即可。不要乱动sudo
,尤其是那些sudo su
如今似乎很流行的不必要的混乱。
答案2
直接的问题是您的“shell 命令”,即su
,需要输入(密码),这与 SFTP 协议不兼容。如 WinSCP FAQ登录后如何更改用户(例如 su root)?说:
但是您将无法提供密码...因此,只有在不需要输入密码的情况
su
下才允许您执行上述操作。sudo su
有关详细信息,请参阅常见问题解答。
正如常见问题解答所述(@roaima 也已经回答过),直接使用帐户登录root
,而不是使用su
。另请参阅允许使用 SSH 在 Linux 上以 root 身份自动执行命令。