将 SSH 用户限制为 shell 命令 [英] Limit SSH User to a shell command
问题描述
如何允许用户通过 ssh 连接到我的服务器,但仅限于 shell 命令和目录?
how can I allow an user to ssh to my server with limitation to a shell command and a directory?
我正在使用 git 将代码部署到我的服务器.我有 2 个服务器,第一个是产品服务器,第二个是 git 服务器.
I'm using git to deploy code to my Server. I have 2 servers, 1st one is product server, 2nd one is a git server.
我的团队使用 git 服务器来拉/推代码.
My team use git server to pull/push code.
在我的产品服务器上,我设置了 git 客户端.每当我想发布一个版本时,我都会将它推送到我的 git 服务器(master 或其他分支......),然后我 ssh 到我的产品服务器来拉取代码.
At my product server, I setup git client. Whenever I want to publish a version, I push it to my git server (master or other branches ...), then I ssh into my product server to pull the code.
我想和我的队友分享代码拉取权限,但不想让他们运行除了git之外的任何命令,并且只限制他们在一个目录中.
I want to share the code pulling privilege with my teammates, but don't want to allow them to run any command but git, and limit them in a directory only.
我想限制的目录的所有者是apache:apache,所以如果ssh用户以apache权限运行会很好.
The owner of directory that I want to limit is apache:apache, so it will be very good if the ssh user run by apache privilege.
谢谢,
已解决:我使用了 lshell 和一组有限的命令.
Solved: I've used lshell with a limit set of commands.
推荐答案
在 git 用户中禁用 shell 的一个简单命令是将 /usr/bin/bash 替换为 /usr/bin/git-shell.在/etc/password 文件中或使用以下命令替换它:
A simple command to disable the shell in a git user is to replace the /usr/bin/bash with /usr/bin/git-shell. Replace it in the /etc/password file or using the command:
usermod -s /usr/bin/git-shell [username]
从 Git 官方网站查看此文档:设置服务器.如果您想在其上使用外壳但将其限制为目录使用,则附加信息:rbash.与 git-shell 相同,只是用它替换用户 shell.
Check this document from the official Git website: Setting Up the Server. Additional info if you want to have a shell on it but limiting it to a directory use: rbash. Same as git-shell just replace the user shell with it.
这篇关于将 SSH 用户限制为 shell 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!