堡壘機介紹
搭建簡易堡壘機
搭建簡易堡壘機 – jailkit chroot
wget https://olivier.sessink.nl/jailkit/jailkit-2.19.tar.bz2 tar jxvf jailkit-2.19.tar.bz2 cd jailkit-2.19 ./configure && make && make install mkdir /home/jail jk_init -v -j /home/jail/ basicshell jk_init -v -j /home/jail/ editors jk_init -v -j /home/jail/ netutils jk_init -v -j /home/jail/ ssh mkdir /home/jail/usr/sbin cp /usr/sbin/jk_lsh /home/jail/usr/sbin/jk_lsh useradd zhangsan passwd zhangsan jk_jailuser -m -j /home/jail zhangsan vim /home/jail/etc/passwd //把zhangsan那一行的/usr/sbin/jk_lsh改成/bin/bash
日誌審計
如下操做是須要在全部被登陸機器上作的html
mkdir /usr/local/records chmod 777 !$ chmod +t !$ vi /etc/profile //添加 if [ ! -d /usr/local/records/${LOGNAME} ] then mkdir -p /usr/local/records/${LOGNAME} chmod 300 /usr/local/records/${LOGNAME} fi export HISTORY_FILE="/usr/local/records/${LOGNAME}/bash_history" export PROMPT_COMMAND='{ date "+%Y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >>$HISTORY_FILE'
開源堡壘機jumpserver介紹
Jumpserver安裝
官方安裝指導http://docs.jumpserver.org/zh/docs/setup_by_centos.html前端
測試推薦環境
- CPU: 64位雙核處理器
- 內存: 4G DDR3
- 數據庫:mysql 版本大於等於 5.6 mariadb 版本大於等於 5.5.6
環境
- 系統: CentOS 7
- IP: 192.168.244.144
- 設置 selinux 和防火牆
$ firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口 $ firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用戶SSH登陸端口 coco $ firewall-cmd --reload # 從新載入規則 $ setenforce 0 $ sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config # 修改字符集, 不然可能報 input/output error的問題, 由於日誌裏打印了中文 $ localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 $ export LC_ALL=zh_CN.UTF-8 $ echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
一. 準備 Python3 和 Python 虛擬環境java
1.1 安裝依賴包python
[root@harry-02 ~]# yum -y install wget gcc epel-release git
1.2 安裝 Python3.6mysql
[root@harry-02 ~]#yum -y install python36 python36-devel 若是下載速度很慢, 能夠換國內源 [root@harry-02 ~]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo [root@harry-02 ~]#yum -y install python36 python36-devel
1.3 創建 Python 虛擬環境linux
由於 CentOS 7 自帶的是 Python2, 而 Yum 等工具依賴原來的 Python, 爲了避免擾亂原來的環境咱們來使用 Python 虛擬環境nginx
[root@harry-02 ~]# cd /opt/ [root@harry-02 opt]# python3.6 -m venv py3 [root@harry-02 opt]# source /opt/py3/bin/activate # 看到下面的提示符表明成功, 之後運行 Jumpserver 都要先運行以上 source 命令, 如下全部命令均在該虛擬環境中運行 (py3) [root@harry-02 opt]#
二. 安裝 Jumpserver
2.1 下載或 Clone 項目git
項目提交較多 git clone 時較大, 你能夠選擇去 Github 項目頁面直接下載zip包。github
(py3) [root@harry-02 opt]# cd /opt/ (py3) [root@harry-02 opt]# git clone --depth=1 https://github.com/jumpserver/jumpserver.git 正克隆到 'jumpserver'...
2.2 安裝依賴 RPM 包web
cd /opt/jumpserver/requirements yum -y install $(cat rpm_requirements.txt) # 若是沒有任何報錯請繼續
2.3 安裝 Python 庫依賴
pip install --upgrade pip setuptools pip install -r requirements.txt # 若是下載速度很慢, 能夠換國內源 pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
2.4 安裝 Redis, Jumpserver 使用 Redis 作 cache 和 celery broke
yum -y install redis systemctl enable redis systemctl start redis
2.5 安裝 MySQL
本教程使用 Mysql 做爲數據庫, 若是不使用 Mysql 能夠跳過相關 Mysql 安裝和配置
yum -y install mariadb mariadb-devel mariadb-server # centos7下安裝的是mariadb systemctl enable mariadb systemctl start mariadb
2.6 建立數據庫 Jumpserver 並受權
DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` # 生成隨機數據庫密碼 echo -e "\033[31m 你的數據庫密碼是 $DB_PASSWORD \033[0m" mysql -uroot -e "create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD'; flush privileges;"
2.7 修改 Jumpserver 配置文件
$ cd /opt/jumpserver $ cp config_example.yml config.yml $ SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50` # 生成隨機SECRET_KEY $ echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc $ BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16` # 生成隨機BOOTSTRAP_TOKEN $ echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc $ sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml $ sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml $ sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml $ sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml $ sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml $ sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml $ echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m" $ echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m" $ vi config.yml # 確認內容有沒有錯誤
# SECURITY WARNING: keep the secret key used in production secret! # 加密祕鑰 生產環境中請修改成隨機字符串, 請勿外泄 SECRET_KEY: # SECURITY WARNING: keep the bootstrap token used in production secret! # 預共享Token coco和guacamole用來註冊服務帳號, 不在使用原來的註冊接受機制 BOOTSTRAP_TOKEN: # Development env open this, when error occur display the full process track, Production disable it # DEBUG 模式 開啓DEBUG後遇到錯誤時能夠看到更多日誌 DEBUG: false # DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/ # 日誌級別 LOG_LEVEL: ERROR # LOG_DIR: # Session expiration setting, Default 24 hour, Also set expired on on browser close # 瀏覽器Session過時時間, 默認24小時, 也能夠設置瀏覽器關閉則過時 # SESSION_COOKIE_AGE: 86400 SESSION_EXPIRE_AT_BROWSER_CLOSE: true # Database setting, Support sqlite3, mysql, postgres .... # 數據庫設置 # See https://docs.djangoproject.com/en/1.10/ref/settings/#databases # SQLite setting: # 使用單文件sqlite數據庫 # DB_ENGINE: sqlite3 # DB_NAME: # MySQL or postgres setting like: # 使用Mysql做爲數據庫 DB_ENGINE: mysql DB_HOST: 127.0.0.1 DB_PORT: 3306 DB_USER: jumpserver DB_PASSWORD: DB_NAME: jumpserver # When Django start it will bind this host and port # ./manage.py runserver 127.0.0.1:8080 # 運行時綁定端口 HTTP_BIND_HOST: 0.0.0.0 HTTP_LISTEN_PORT: 8080 # Use Redis as broker for celery and web socket # Redis配置 REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 # REDIS_PASSWORD: # REDIS_DB_CELERY: 3 # REDIS_DB_CACHE: 4 # Use OpenID authorization # 使用OpenID 來進行認證設置 # BASE_SITE_URL: http://localhost:8080 # AUTH_OPENID: false # True or False # AUTH_OPENID_SERVER_URL: https://openid-auth-server.com/ # AUTH_OPENID_REALM_NAME: realm-name # AUTH_OPENID_CLIENT_ID: client-id # AUTH_OPENID_CLIENT_SECRET: client-secret # OTP settings # OTP/MFA 配置 # OTP_VALID_WINDOW: 0 # OTP_ISSUER_NAME: Jumpserver
2.8 運行 Jumpserver
$ cd /opt/jumpserver $ ./jms start all -d # 後臺運行使用 -d 參數./jms start all -d # 新版本更新了運行腳本, 使用方式./jms start|stop|status all 後臺運行請添加 -d 參數
三. 安裝 SSH Server 和 WebSocket Server: Coco
3.1 下載或 Clone 項目
cd /opt source /opt/py3/bin/activate git clone --depth=1 https://github.com/jumpserver/coco.git
3.2 安裝依賴
cd /opt/coco/requirements yum -y install $(cat rpm_requirements.txt) pip install -r requirements.txt # 若是下載速度很慢, 能夠換國內源 $ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
3.3 修改配置文件並運行
cd /opt/coco cp config_example.yml config.yml sed -i "s/BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>/BOOTSTRAP_TOKEN: BOOTSTRAP_TOKEN/g" /opt/coco/config.yml sed -i "s/# LOG_LEVEL: INFO/LOG_LEVEL: ERROR/g" /opt/coco/config.yml vi config.yml
# 項目名稱, 會用來向Jumpserver註冊, 識別而已, 不能重複 # NAME: {{ Hostname }} # Jumpserver項目的url, api請求註冊會使用 CORE_HOST: http://127.0.0.1:8080 # Bootstrap Token, 預共享祕鑰, 用來註冊coco使用的service account和terminal # 請和jumpserver 配置文件中保持一致, 註冊完成後能夠刪除 BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver> # 啓動時綁定的ip, 默認 0.0.0.0 # BIND_HOST: 0.0.0.0 # 監聽的SSH端口號, 默認2222 # SSHD_PORT: 2222 # 監聽的HTTP/WS端口號, 默認5000 # HTTPD_PORT: 5000 # 項目使用的ACCESS KEY, 默認會註冊, 並保存到 ACCESS_KEY_STORE中, # 若是有需求, 能夠寫到配置文件中, 格式 access_key_id:access_key_secret # ACCESS_KEY: null # ACCESS KEY 保存的地址, 默認註冊後會保存到該文件中 # ACCESS_KEY_STORE: data/keys/.access_key # 加密密鑰 # SECRET_KEY: null # 設置日誌級別 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL] LOG_LEVEL: ERROR # 日誌存放的目錄 # LOG_DIR: logs # SSH白名單 # ALLOW_SSH_USER: all # SSH黑名單, 若是用戶同時在白名單和黑名單, 黑名單優先生效 # BLOCK_SSH_USER: # - # 和Jumpserver 保持心跳時間間隔 # HEARTBEAT_INTERVAL: 5 # Admin的名字, 出問題會提示給用戶 # ADMINS: '' # SSH鏈接超時時間 (default 15 seconds) # SSH_TIMEOUT: 15 # 語言 [en, zh] # LANGUAGE_CODE: zh # SFTP的根目錄, 可選 /tmp, Home其餘自定義目錄 # SFTP_ROOT: /tmp # SFTP是否顯示隱藏文件 # SFTP_SHOW_HIDDEN_FILE: false
./cocod start -d # 後臺運行使用 -d 參數./cocod start -d # 新版本更新了運行腳本, 使用方式./cocod start|stop|status 後臺運行請添加 -d 參數
四. 安裝 Web Terminal 前端: Luna
Luna 已改成純前端, 須要 Nginx 來運行訪問
訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包, 直接解壓不須要編譯
4.1 解壓 Luna
$ cd /opt $ wget https://github.com/jumpserver/luna/releases/download/1.4.9/luna.tar.gz # 若是網絡有問題致使下載沒法完成可使用下面地址 $ wget https://demo.jumpserver.org/download/luna/1.4.9/luna.tar.gz $ tar xf luna.tar.gz $ chown -R root:root luna
五. 安裝 Windows 支持組件(若是不須要管理 windows 資產, 能夠直接跳過這一步)
5.1 安裝依賴
$ rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro $ rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm $ yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm $ yum install -y java-1.8.0-openjdk libtool $ yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel $ yum install -y ffmpeg-devel freerdp-devel freerdp-plugins pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel ghostscript $ ln -s /usr/local/lib/freerdp/*.so /usr/lib64/freerdp/
5.2 編譯安裝 guacamole 服務
$ cd /opt $ git clone --depth=1 https://github.com/jumpserver/docker-guacamole.git $ cd /opt/docker-guacamole/ $ tar -xf guacamole-server-0.9.14.tar.gz $ cd guacamole-server-0.9.14 $ autoreconf -fi $ ./configure --with-init-dir=/etc/init.d $ make && make install $ cd .. $ rm -rf guacamole-server-0.9.14 $ ldconfig
5.3 配置 Tomcat
$ mkdir -p /config/guacamole /config/guacamole/lib /config/guacamole/extensions # 建立 guacamole 目錄 $ ln -sf /opt/docker-guacamole/guacamole-auth-jumpserver-0.9.14.jar /config/guacamole/extensions/guacamole-auth-jumpserver-0.9.14.jar $ ln -sf /opt/docker-guacamole/root/app/guacamole/guacamole.properties /config/guacamole/guacamole.properties # guacamole 配置文件 $ cd /config $ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.40/bin/apache-tomcat-8.5.40.tar.gz $ tar xf apache-tomcat-8.5.40.tar.gz $ rm -rf apache-tomcat-8.5.40.tar.gz $ mv apache-tomcat-8.5.40 tomcat8 $ rm -rf /config/tomcat8/webapps/* $ ln -sf /opt/docker-guacamole/guacamole-0.9.14.war /config/tomcat8/webapps/ROOT.war # guacamole client $ sed -i 's/Connector port="8080"/Connector port="8081"/g' /config/tomcat8/conf/server.xml # 修改默認端口爲 8081 $ sed -i 's/FINE/WARNING/g' /config/tomcat8/conf/logging.properties # 修改 log 等級爲 WARNING $ cd /config $ wget https://github.com/ibuler/ssh-forward/releases/download/v0.0.5/linux-amd64.tar.gz # 若是網絡有問題致使下載沒法完成可使用下面地址 $ wget https://demo.jumpserver.org/download/ssh-forward/v0.0.5/linux-amd64.tar.gz $ tar xf linux-amd64.tar.gz -C /bin/ $ chmod +x /bin/ssh-forward
5.4 配置環境變量
# 勿屢次執行如下環境設置 $ export JUMPSERVER_SERVER=http://127.0.0.1:8080 # http://127.0.0.1:8080 指 jumpserver 訪問地址 $ echo "export JUMPSERVER_SERVER=http://127.0.0.1:8080" >> ~/.bashrc # BOOTSTRAP_TOKEN 爲 Jumpserver/config.yml 裏面的 BOOTSTRAP_TOKEN $ export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN $ echo "export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc $ export JUMPSERVER_KEY_DIR=/config/guacamole/keys $ echo "export JUMPSERVER_KEY_DIR=/config/guacamole/keys" >> ~/.bashrc $ export GUACAMOLE_HOME=/config/guacamole $ echo "export GUACAMOLE_HOME=/config/guacamole" >> ~/.bashrc
5.5 啓動 Guacamole
$ /etc/init.d/guacd start $ sh /config/tomcat8/bin/startup.sh
六. 配置 Nginx 整合各組件
6.1 安裝 Nginx
$ yum install yum-utils $ vi /etc/yum.repos.d/nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key $ yum makecache fast $ yum install -y nginx $ rm -rf /etc/nginx/conf.d/default.conf $ systemctl enable nginx
6.3 準備配置文件 修改 /etc/nginx/conf.d/jumpserver.conf
$ vi /etc/nginx/conf.d/jumpserver.conf server { listen 80; # 代理端口, 之後將經過此端口進行訪問, 再也不經過8080端口 # server_name demo.jumpserver.org; # 修改爲你的域名或者註釋掉 client_max_body_size 100m; # 錄像及文件上傳大小限制 location /luna/ { try_files $uri / /index.html; alias /opt/luna/; # luna 路徑, 若是修改安裝目錄, 此處須要修改 } location /media/ { add_header Content-Encoding gzip; root /opt/jumpserver/data/; # 錄像位置, 若是修改安裝目錄, 此處須要修改 } location /static/ { root /opt/jumpserver/data/; # 靜態資源, 若是修改安裝目錄, 此處須要修改 } location /socket.io/ { proxy_pass http://localhost:5000/socket.io/; # 若是coco安裝在別的服務器, 請填寫它的ip proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /coco/ { proxy_pass http://localhost:5000/coco/; # 若是coco安裝在別的服務器, 請填寫它的ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /guacamole/ { proxy_pass http://localhost:8081/; # 若是guacamole安裝在別的服務器, 請填寫它的ip proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location / { proxy_pass http://localhost:8080; # 若是jumpserver安裝在別的服務器, 請填寫它的ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
6.3 運行 Nginx
nginx -t # 確保配置沒有問題, 有問題請先解決 # CentOS 7 $ systemctl start nginx $ systemctl enable nginx
6.4 開始使用 Jumpserver
檢查應用是否已經正常運行
服務所有啓動後, 訪問 http://192.168.244.144, 訪問nginx代理的端口, 不要再經過8080端口訪問
默認帳號: admin 密碼: admin
到Jumpserver 會話管理-終端管理 檢查 Coco Guacamole 等應用的註冊