大网数据广告活动
服务器运维问答

SSH without invoking shell

· 52CE 我爱测

I've managed to mess up some shared libraries on my system, and now my shell cannot be run, thus locking me out of the system. Both ssh , sftp , and scp , as configured on the remote system, seem to rely on the shell, so those al…

问题原文

原帖链接 · A__A__0 · CC BY-SA 3.0

I've managed to mess up some shared libraries on my system, and now my shell cannot be run, thus locking me out of the system. Both ssh, sftp, and scp, as configured on the remote system, seem to rely on the shell, so those alternatives are out. Really, it is not a big issue because I have some remote hands that can change my shell to sh via console.

However I'm curious, getting down to the mechanics of the SSH protocol, whether it is possible to authenticate and perform some manipulations on the remote system (eg, modifying /etc/passwd), without ever invoking the shell?

EDIT

Just to be fair, to the fellow who suggested specifying the alternative command/shell after the ssh command string (eg, ssh myhost /bin/sh): the man page does state:

If command is specified, it is executed on the remote host instead of a login shell.

which could definitely be confusing.

社区高分解答

原帖链接 · xhienne · CC BY-SA 4.0

[for the record only -- at the time of writing, the problem has long been fixed, hopefully]

With openssh, ANY command executed by sshd is executed via your login shell with the -c option:

  • command passed in the ssh command line (i.e. ssh user@host command)
  • command set up in the .authorized_keys file (i.e. command="..." ssh-rsa AAAA...)
  • command specified by the ForceCommand option in sshd_config
  • the execution of the ~/.ssh/rc script (via /bin/sh ~/.ssh/rc)
  • even the scp commands local to a server executed in response to a remote scp

So, if your login shell is faked (/bin/false or nologin) or broken, there is no way for you to execute anything remotely with ssh. That's also why no alternative shell is possible.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-08-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。