1. 程式人生 > >用lshell+腳本實現堡壘機(跳轉機)功能

用lshell+腳本實現堡壘機(跳轉機)功能

跳轉機 堡壘機 lshell

堡壘機(跳轉機)功能:

讓需要登錄生產服務器的用戶必須先登錄這臺服務器,再從這臺服務器上登錄到生產服務器。

可以限制只使用ssh和exit命令,或者自己寫個腳本讓登錄的人自己選擇。


這裏可以在堡壘機(跳轉機)服務器上安裝lshell來達到各種限制的功能。


1、安裝lshell工具
gif主頁:https://github.com/ghantoos/lshell

如果堡壘機沒有聯網,可以從別的地方下載安裝文件,再復制過來。

git clone https://github.com/ghantoos/lshell.git
cd lshell
python setup.py install –no-compile –install-scripts=/usr/bin/

如果沒報錯,即安裝成功。

2、配置conf
配置好這個文件,就能達到很好的效果。
vim /etc/lshell.conf

[default]

allowed : ['ssh','exit']


3、改變用戶默認shell,使用lshell作為默認shell:
# cp /etc/lshell.conf /usr/local/etc/
# chsh -s /usr/bin/lshell user_name 這個命令只能修改某個用戶的,可以寫個腳本來批量修改

4、開啟日誌
為了記錄用戶日誌,需要創建相關目錄
# addgroup –system lshell
# mkdir /var/log/lshell

# chown :lshell /var/log/lshell
# chmod 770 /var/log/lshell

然後增加用戶到lshell group:
# usermod -aG lshell user_name

# 更多文章見我個人站點:haibing.org #

用lshell+腳本實現堡壘機(跳轉機)功能