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

2023-10-17 16:44

本文主要是介绍【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/226673

相关文章

C++变换迭代器使用方法小结

《C++变换迭代器使用方法小结》本文主要介绍了C++变换迭代器使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1、源码2、代码解析代码解析:transform_iterator1. transform_iterat

C++中std::distance使用方法示例

《C++中std::distance使用方法示例》std::distance是C++标准库中的一个函数,用于计算两个迭代器之间的距离,本文主要介绍了C++中std::distance使用方法示例,具... 目录语法使用方式解释示例输出:其他说明:总结std::distance&n编程bsp;是 C++ 标准

vue使用docxtemplater导出word

《vue使用docxtemplater导出word》docxtemplater是一种邮件合并工具,以编程方式使用并处理条件、循环,并且可以扩展以插入任何内容,下面我们来看看如何使用docxtempl... 目录docxtemplatervue使用docxtemplater导出word安装常用语法 封装导出方

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Elasticsearch 在 Java 中的使用教程

《Elasticsearch在Java中的使用教程》Elasticsearch是一个分布式搜索和分析引擎,基于ApacheLucene构建,能够实现实时数据的存储、搜索、和分析,它广泛应用于全文... 目录1. Elasticsearch 简介2. 环境准备2.1 安装 Elasticsearch2.2 J

使用C#代码在PDF文档中添加、删除和替换图片

《使用C#代码在PDF文档中添加、删除和替换图片》在当今数字化文档处理场景中,动态操作PDF文档中的图像已成为企业级应用开发的核心需求之一,本文将介绍如何在.NET平台使用C#代码在PDF文档中添加、... 目录引言用C#添加图片到PDF文档用C#删除PDF文档中的图片用C#替换PDF文档中的图片引言在当

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1