【MultiOTP】在Linux上使用MultiOTP进行SSH登录

2023-10-17 20:30

本文主要是介绍【MultiOTP】在Linux上使用MultiOTP进行SSH登录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在前面的文章中【FreeRADIUS】使用FreeRADIUS进行SSH身份验证已经了解过如何通过Radius去来实现SSH和SUDO的登录,在接下来的文章中只是将密码从【LDAP PASSWORD + Googlt OTP】改成了【MultiOTP】生成的passcode,不在需要密码,只需要OTP去登录。这样再也不用担心密码忘记了。

拓扑图

在这里插入图片描述

前提条件:

  1. 一台提供RADIUS服务的MultiOTP服务器,如何配置可参考【MultiOTP】Docker安裝MultiOTP, 让Windows登入更安全(MFA)
  2. 一台客户端【Ubuntu 22.04】,sudo权限的用户
  3. 两台设备之间可以互通

实施:

0. 在MultiOTP服务器上修改clients.conf定义哪些设备被允许连接到RADIUS服务器

root@multiotp-Virtual-Machine:/home/ud# cat  /multiotp/freeradius/config/3.0/clients.conf
# -*- text -*-
##
## clients.conf -- client configuration directives
##... ...client 0.0.0.0/0  { # multiotp my-first-network
secret = myfirstpass # multiotp my-first-network
shortname = my-first-network # multiotp my-first-network
} # multiotp my-first-network
# multiotp my-first-network END

1. 安装必要的软件包,以便客户端可以通过以下命令与FreeRADIUS进行交互

apt-get install libpam-radius-auth freeradius-utils -y
root@ud-Virtual-Machine:/home/ud# apt-get install libpam-radius-auth freeradius-utils -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
freeradius-utils is already the newest version (3.0.26~dfsg~git20220223.1.00ed0241fa-0ubuntu3.1).
The following NEW packages will be installed:libpam-radius-auth
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.4 kB of archives.
After this operation, 84.0 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 libpam-radius-auth amd64 2.0.0-1 [25.4 kB]
Fetched 25.4 kB in 8s (3,342 B/s)
Selecting previously unselected package libpam-radius-auth.
(Reading database ... 182939 files and directories currently installed.)
Preparing to unpack .../libpam-radius-auth_2.0.0-1_amd64.deb ...
Unpacking libpam-radius-auth (2.0.0-1) ...
Setting up libpam-radius-auth (2.0.0-1) ...

2. 修改配置文件

i. 编辑/etc/pam_radius_auth.conf文件,并注释掉默认的4行。然后添加一行,指定RADIUS服务器的IP地址和共享密钥。

root@ud-Virtual-Machine:/home/ud# cat /etc/pam_radius_auth.conf
#  pam_radius_auth configuration file.  Copy to: /etc/raddb/server
#
......
#  Note: specifying a source_ip field is mandatory due to config parsing,
#  but if not needed it can be just set to 0.
#
# server[:port]             shared_secret      timeout (s)  source_ip            vrf
#127.0.0.1                   secret             3
#other-server                other-secret       5            192.168.1.10         vrf-blue
#[2001:0db8:85a3::4]:1812    other6-secret      3            [2001:0db8:85a3::3]  vrf-red
#other-other-server          other-other-secret 5            0                    vrf-blue
10.2.112.4:1812              myfirstpass         30
#
# having localhost in your radius configuration is a Good Thing.
#
# See the INSTALL file for pam.conf hints.

ii. 编辑/etc/ssh/sshd_config文件,启用ssh服务中的PAM认证。

root@ud-Virtual-Machine:/home/ud# cat /etc/ssh/sshd_config# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
......
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
ChallengeResponseAuthentication yes
#PermitEmptyPasswords no
......
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
......

iii. 编辑/etc/pam.d/sshd文件,启用带有Radius的PAM模块。

root@ud-Virtual-Machine:/home/ud# cat /etc/pam.d/sshd
# PAM configuration for the Secure Shell service#Radius authentication
auth sufficient pam_radius_auth.so
......
root@ud-Virtual-Machine:/home/ud#

3. 重启SSHD服务

service ssh restart

4. 添加本地账户

root@ud-Virtual-Machine:/home/ud# adduser knightyang --disabled-password --quiet --gecos ""

sudo同时也需要使用MultiOTP认证的话需要修改以下:

1. 编辑/etc/pam.d/sudo文件,启用带有Radius的PAM模块

root@ud-Virtual-Machine:/home/ud# cat /etc/pam.d/sudo
#%PAM-1.0auth sufficient pam_radius_auth.so# Set up user limits from /etc/security/limits.conf.
session    required   pam_limits.sosession    required   pam_env.so readenv=1 user_readenv=0
session    required   pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0@include common-auth
@include common-account
@include common-session-noninteractive
root@ud-Virtual-Machine:/home/ud#

2. 给用户添加sudo权限

root@ud-Virtual-Machine:sudo usermod -aG sudo knightyang

这篇关于【MultiOTP】在Linux上使用MultiOTP进行SSH登录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/227787

相关文章

Python使用Pandas对比两列数据取最大值的五种方法

《Python使用Pandas对比两列数据取最大值的五种方法》本文主要介绍使用Pandas对比两列数据取最大值的五种方法,包括使用max方法、apply方法结合lambda函数、函数、clip方法、w... 目录引言一、使用max方法二、使用apply方法结合lambda函数三、使用np.maximum函数

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

Python调用Orator ORM进行数据库操作

《Python调用OratorORM进行数据库操作》OratorORM是一个功能丰富且灵活的PythonORM库,旨在简化数据库操作,它支持多种数据库并提供了简洁且直观的API,下面我们就... 目录Orator ORM 主要特点安装使用示例总结Orator ORM 是一个功能丰富且灵活的 python O

Nginx设置连接超时并进行测试的方法步骤

《Nginx设置连接超时并进行测试的方法步骤》在高并发场景下,如果客户端与服务器的连接长时间未响应,会占用大量的系统资源,影响其他正常请求的处理效率,为了解决这个问题,可以通过设置Nginx的连接... 目录设置连接超时目的操作步骤测试连接超时测试方法:总结:设置连接超时目的设置客户端与服务器之间的连接

Java中String字符串使用避坑指南

《Java中String字符串使用避坑指南》Java中的String字符串是我们日常编程中用得最多的类之一,看似简单的String使用,却隐藏着不少“坑”,如果不注意,可能会导致性能问题、意外的错误容... 目录8个避坑点如下:1. 字符串的不可变性:每次修改都创建新对象2. 使用 == 比较字符串,陷阱满

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定

Linux使用nload监控网络流量的方法

《Linux使用nload监控网络流量的方法》Linux中的nload命令是一个用于实时监控网络流量的工具,它提供了传入和传出流量的可视化表示,帮助用户一目了然地了解网络活动,本文给大家介绍了Linu... 目录简介安装示例用法基础用法指定网络接口限制显示特定流量类型指定刷新率设置流量速率的显示单位监控多个

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署