Linux下只允许用户远程scp

jopen 9年前

本文将介绍在Linux环境下,让用户不能远程登录 只能使用scp命令 

使用到的软件:rssh(http://pizzashack.org/rssh/index.shtml )

环境:centos6.x

配置好eple源

curl firxiao.com/sh/chrepo.sh|sh


将自动配置base 及epel源为阿里云的源。


安装rssh

yum install -y rssh



安装完会多一个二进制的rssh

ls -l /usr/bin/rssh   -rwxr-x---. 1 root rsshusers 25816 10月  1 02:10 /usr/bin/rssh



配置用户

添加一个test用户并给给予一个密码。  注意用户组及赋予给它的默认shell

useradd test -g rsshusers -s /usr/bin/rssh  echo "test"|passwd --stdin test



对于已经存在的用户可以将其用户组改为rsshusers ,默认shell改为 /usr/bin/rssh 即可

  如下命令

usermod -G rsshusers -s /usr/bin/rssh  user_exists



配置rssh

rssh配置文件位于/etc/rssh.conf

在配置文件最后添加

allowscp


验证

第一步 ssh验证

  ssh test@localhost 进行验证

#ssh test@localhost  This account is restricted by rssh.  Allowed commands: scp   If you believe this is in error, please contact your system administrator.  Connection to localhost closed.


第二步 scp验证

scp install.log test@localhost:/home/test  test@localhost's password:   install.log                                  100% 9169     9.0KB/s   00:00



至此配置完成