需要注意的是,目前所有(获得授权的)开发者用户都能以系统用户 git 的身份登录服务器从而获得一个普通shell。
如果你想对此加以限制,则需要修改 passwd 文件中(git 用户所对应)的 shell 值。
借助一个名为 git-shell 的受限 shell 工具,你可以方便地将用户 git 的活动限制在与 Git 相关的范围内。
该工具随 Git 软件包一同提供。
如果将 git-shell 设置为用户 git 的登录 shell(login shell),那么用户 git便不能获得此服务器的普通 shell 访问权限。
若要使用 git-shell,需要用它替换掉 bash 或 csh,使其成为系统用户的登录 shell。
为进行上述操作,首先你必须确保 git-shell 已存在于 /etc/shells 文件中:
# cat /etc/shells # see if `git-shell` is already in there. If not...
# which git-shell # make sure git-shell is installed on your system.
# sudo vim /etc/shells # and add the path to git-shell from last command
现在你可以使用 chsh <username> 命令修改任一系统用户的 shell:
# sudo chsh git # and enter the path to git-shell, usually: /usr/bin/git-
shell
这样,用户 git 就只能利用 SSH 连接对 Git 仓库进行推送和拉取操作,而不能登录机器并取得普通 shell。如果试图登录,你会发现尝试被拒绝,像这样:
# ssh git@gitserver
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to gitserver closed.
现在,网络相关的 Git 命令依然能够正常工作,但是开发者用户已经无法得到一个普通 shell 了。
正如输出信息所提示的,你也可以在 git 用户的家目录下建立一个目录,来对 git-shell 命令进行一定程度的自定义。
比如,你可以限制掉某些本应被服务器接受的 Git 命令,或者对刚才的 SSH 拒绝登录信息进行自定义,这样,当有开发者用户以类似方式尝试登录时,便会看到你的信息。
要了解更多有关自定义 shell 的信息,请运行 git help shell。
操作汇总:
1、客户端(用户)操作
1.1 生成SSH公钥
# ssh-keygen
默认存储位置:~/.ssh
1.2 把生成的公钥发送给服务端(git)
# cat ~/.ssh/id_rsa.pub
2、服务端操作
2.1 添加git帐号
注:git$ 说明是使用git用户操作的
# adduser git
# su git
git$ mkdir .ssh && chmod 700 .ssh
git$touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
2.2 把客户端发送过来的公钥添加到authorized_keys 文件的末尾
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/sanxing/article-72418-8.html
而雷军却又说小米手机在中国占有率第一
当然凭他的数学水平也确实管不了
果然是美国带着日韩玩