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

Linux - Limit user to one application in ssh

· 52CE 我爱测

This is something that I looked into a while back and found some useful info for... but now that I actually need to do it, of course I can't find that guide I saw anymore. Anyways, here's the situation. I have a program that runs…

问题原文

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

This is something that I looked into a while back and found some useful info for... but now that I actually need to do it, of course I can't find that guide I saw anymore.

Anyways, here's the situation. I have a program that runs using an ncurses menu through SSH. I want users to be able to login to that program via SSH, but only to that program.

What do I have to do so that this scenario is possible?

  • User opens Putty
  • User signs into the Linux server with their username and password
  • When logging in, they go straight to that program
  • In the even of a program close, crash, cancellation, etc... the user is forcefully loged off of the system.

My goal is to limit them from seeing a command line at all, and to be restricted to just that program. Is this possible? How do I/would I go about doing it?

社区高分解答

原帖链接 · John Mahowald · CC BY-SA 3.0

This is also called a captive login.

Append to the user's ~/.profile an execution of the program and an exit.

exec /usr/local/bin/program
exit

Clever users know they can supply a command in their ssh client that isn't the shell you expect. Prevent that with ForceCommand in your sshd config:

ForceCommand

Forces the execution of the command specified by ForceCommand, ignoring any command supplied by the client and ~/.ssh/rc if present. The command is invoked by using the user's login shell with the -c option. This applies to shell, command, or subsystem execution. It is most useful inside a Match block.

Match Group programusers
    ForceCommand /usr/local/bin/program

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

资料来源与适用范围

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

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

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