Linux下只允许用户远程scp

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

使用到的软件:rssh(rssh - restricted shell for scp/sftp )

环境:centos6.x

配置好epel源

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

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

安装rssh

 
  1. yum install -y rssh

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

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

配置用户

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

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

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

如下命令

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

配置rssh

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

在配置文件最后添加

 
  1. allowscp

验证

第一步 ssh验证

ssh test@localhost 进行验证

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

第二步 scp验证

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

至此配置完成

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值