設置一個ssh client by web

參考

https://github.com/huashengdun/websshnginx

先安裝docker和docker-compose,詳細不說了git

安裝

git clone下來

git clone https://github.com/huashengdun/webssh.git

運行

第一次運行會須要時間下載各類包,時間大概10分鐘 第二次直接運行,大概2秒github

cd webssh
docker-compose up
#或者後臺運行
docker-compose up -d

使用

沒有配置nginx

若是沒有配置nginx,那不用看訪問限制那段了,直接用ip加8888端口便可訪問到頁面 例如我這臺服務器的ip是10.2.10.52,那我只要再瀏覽器裏輸入http://10.2.10.52:8888 就能訪問到了web

配置了nginx

訪問xxx.xxx.com便可,nginx內部會將請求轉給webssh的,具體要看nginx如何配置了
具體參考下面的訪問限制段落docker

訪問限制

因爲ssh的敏感性,webssh只監聽私有網段的ip,若是用公網ip訪問則拒絕 若是想用公網也能訪問,前面放個nginx便可瀏覽器

server {
    listen  80;
    server_name     xxx.xxx.com;

    auth_basic      "who";
    auth_basic_user_file /etc/nginx/userpassword.db;
    location / {
            proxy_http_version 1.1;
            proxy_read_timeout 300;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-PORT $remote_port;
            proxy_pass      http://10.2.10.52:8888;
    }
}

注意這裏的proxy_pass用的是內網ip,而不是127.0.0.1,是由於我這個nginx也是跑在docker裏的 若是nginx是跑在本機裏,能夠用127.0.0.1的服務器

另外我多作了個認證ssh

auth_basic      "who";
    auth_basic_user_file /etc/nginx/userpassword.db;

若是不作認證,全部知道url的人均可以拿你這個ssh客戶端用了url

相關文章
相關標籤/搜索