linux下利用一次性口令实现安全管理
作者 黑狐 [译自vpsboard]
Linux服务器一直就是以稳定、高效、安全而著称。安全是比较重要的一个环节,这关系到商业机密,更关系到企业的存亡。本文介绍了如何使用optw生成一次性口令及只允许执行特定命令,以下为译文:
我想允许我的朋友登录我的服务器下载一些资料,但是只允许他登录10次,登陆后只允许执行scp命令,不许干别的事情,该怎么办呢?
归纳起来,完成以下2件事情:
- 生成一次性口令
- 只允许用户执行scp任务
实现目标1:生成一次性口令
安装otpw
sudo apt-get install otpw-bin libpam-otpw
配置common-auth
nano /etc/pam.d/common-auth
查找以下行:
auth [success=1 default=ignore] pam_unix.so nullok_secure
在上述行上加入:
auth sufficient pam_otpw.so
session optional pam_otpw.so
用户登录时,首先尝试使用一次性口令登录,失败后,使用正常登录方法。
配置sshd服务
增加一个otpw配置文件:
nano /etc/pam.d/otpw
内容如下:
auth sufficient pam_otpw.so
session optional pam_otpw.so
配置sshd配置文件包含otpw配置文件:
nano /etc/pam.d/sshd
查找:
@include common-auth
在上述行上增加一行:
@include otpw
修改sshd配置文件后,确保以下3个参数设置为yes:
UsePrivilegeSeparation yes
ChallengeResponseAuthentication yes
UsePAM yes
重新启动sshd服务
service ssh restart
这是基本的otpw配置. 确保用户home目录下存在文件配置文件 (~/.otpw) 的用户才会启用一次性口令认证. 所有其它用户不受影响。
下列命令产生4个一次性口令:
otpw-gen -h 5 -w 64
下列命令产生10个一次性口令:
otpw-gen -h 6 -w 79
命令输出如下:
Generating random seed ...
If your paper password list is stolen, the thief should not gain
access to your account with this information alone. Therefore, you
need to memorize and enter below a prefix password. You will have to
enter that each time directly before entering the one-time password
(on the same line).
When you log in, a 3-digit password number will be displayed. It
identifies the one-time password on your list that you have to append
to the prefix password. If another login to your account is in progress
at the same time, several password numbers may be shown and all
corresponding passwords have to be appended after the prefix
password. Best generate a new password list when you have used up half
of the old one.
Overwrite existing password list '~/.otpw' (Y/n)?
Enter new prefix password:
Reenter prefix password:
Creating '~/.otpw'.
Generating new one-time passwords ...
OTPW list generated 2014-02-27 01:31 on kali
000 IT4U V3Bk 002 cfFE g=Gj 004 +2ML Ff92 006 kaag Ar:Y 008 VZY8 iGsp
001 9H7n aPhV 003 fcIJ zf/P 005 Qxqf OhgF 007 zPY/ QJOV 009 :N7K 3zEu
!!! REMEMBER: Enter the PREFIX PASSWORD first !!!
SSH登录:
login as: test
Using keyboard-interactive authentication.
Password 003:
Linux debian 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686
The programs included with the Debian GNU/Linux system are free software;the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jul 9 20:03:23 2013 from 192.168.200.10
test@debian:~$
如果你的前缀口令是 "pass" 实际输入的003号密码是:
passfcIJ zf/P
(前缀密码后不需要输入空格)。
创建optw一次性口令的用户组并添加用户:
addgroup optw
adduser test optw
修改文件权限:
chown root:optw /home/test/.otpw
chmod 640 /home/test/.otpw
禁止其它用户重置口令:
chmod 750 /usr/bin/otpw-gen
目标2.限制用户只允许执行scp任务:
apt-get install rssh
apt-get install scponly
2个定制的shell分别完成以下任务:
rssh限制用户的行为
scponly时仅有scp命令的一个shell.
现在,可以修改用户的shell:
usermod -s /usr/sbin/scponly test
usermod -s /usr/sbin/rssh test
And you can confiure rssh quite descent:
nano /etc/rssh.conf
Content:
# Leave these all commented out to make the default action for rssh to lock
# users out completely...
allowscp
#allowsftp
#allowcvs
#allowrdist
#allowrsync
#allowsvnserve
# if your chroot_path contains spaces, it must be quoted...
# In the following examples, the chroot_path is "/usr/local/my chroot"
user=test:011:000010:"/opt/scpspace/test chroot" # scp with chroot
译者注:
1、optw是linux上的一次性口令的开源实现,类似于RSA公司Secure ID功能。 2、rssh是受限的shell,提供许多实用的功能。配置简单。
- python使用上下文管理器实现sqlite3事务机制
- python服务端多进程压测工具
- 响应式js幻灯片代码一枚
- 使用深度学习检测面部特征,让实时视频聊天变得更有趣
- springboot 注册服务注册中心(zk)的两种方式
- 极速体验:Oracle 18c 下载和Scalable Sequence新特性
- springboot mybatis 事务管理
- Elasticsearch JAVA api轻松搞定groupBy聚合
- 微信加关注链接 一键关注公众号 解决用手机看网页无法扫二维码的烦恼
- springboot mybatis redis 二级缓存
- Elasticsearch强制重置未分配的分片(unassigned)
- 帝国cms调用缩略图和具体文章的方法
- python codis集群客户端(一) - 基于客户端daemon探活与服务列表维护
- python codis集群客户端(二) - 基于zookeeper对实例创建与摘除
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 「性能提升」扩展 Spring Cache 支持多级缓存
- OAuth 2.0 单元测试解决方案
- 聊一聊如何搭建高性能网站哪一些事
- Spring Cloud netflix ribbon源码分析
- 抽奖摇号系统随机性算法介绍
- 翻了翻element-ui源码,发现一个很实用的指令clickoutside
- 自研网关:限流功能的开发
- 如果JSP中无法自动提示EL表达式的解决方法(针对普通项目和maven有不同的方法)
- Android通过ExifInterface判断Camera图片方向的方法
- Python PyQt5整理介绍
- django API 中接口的互相调用实例
- Python Numpy中数据的常用保存与读取方法
- python使用梯度下降和牛顿法寻找Rosenbrock函数最小值实例
- Django Admin设置应用程序及模型顺序方法详解
- 在 Pycharm 安装使用black的方法详解