您好,登錄后才能下訂單哦!
keybox是基于web的ssh終端管理軟件,在生產和測試環境中,服務器一般放在內網中,想要通過外網遠程連接就需要先連接有外網的代理服務器,然后再ssh內網的機器,有了keybox就免去其中的麻煩。
一、安裝
1、安裝java環境,官方建議使用1.8以上的Java JDK
$ yum localinstall -y jdk-8u45-linux-x64.rpm # jdk路徑 $ ls /usr/java/jdk1.8.0_45/ bin COPYRIGHT db include javafx-src.zip jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt $ vim /etc/profile.d/java_env.sh 1 export JAVA_HOME=/usr/java/jdk1.8.0_45 2 export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH $ exec bash # 查看java的版本 $ java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
2、安裝keybox,直接到github上下載keybox壓縮包:https://github.com/skavanagh/KeyBox/releases/
$ tar xf keybox-jetty-v2.89_00.tar.gz -C /usr/local $ cd /usr/local/ $ mv KeyBox-jetty keybox $ cd keybox && ls jetty LICENSE.md README.md startKeyBox.bat startKeyBox.sh
二、啟動keybox
# 初始化并啟動 $ ./startKeyBox.sh 2017-05-10 14:13:02.374:INFO::main: Logging initialized @813ms to org.eclipse.jetty.util.log.StdErrLog 2017-05-10 14:13:02.764:INFO:oejs.Server:main: jetty-9.4.2.v20170220 2017-05-10 14:13:02.812:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/KeyBox-jetty/jetty/webapps/] at interval 1 2017-05-10 14:13:05.084:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=1866ms 2017-05-10 14:13:05.478:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0 2017-05-10 14:13:05.478:INFO:oejs.session:main: No SessionScavenger set, using defaults 2017-05-10 14:13:05.483:INFO:oejs.session:main: Scavenging every 660000ms # 新建數據庫密碼 Please enter database password: Please confirm database password: Setting KeyBox SSH public/private key pair Finger print: 12:70:18:ad:01:45:f5:dd:e2:ac:44:d4:e3:8e:65:d9 KeyBox Generated Global Public Key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfC1IZiTNKgSZZtTHiL8Y8fWTfPlkA/3CUahUs3bp0oZStJNYPAAu6mUAYkDjs6FCoASqrC/WwSVamu504ZUHBID/tKJ1gV4bvjdrlkUDIo3tyhmTl2DpwAPYhaHh+NSvhVyyCFSmicVONhdll2m74p/M7jU/V8jKygNM90FMR9U GdNa7K4VpK1MW6XFax5LlskMVnN93tfwfUXCgWg18/ShbuGF6JLJibMnBI8sVsS3/PTjI/tp+MtvYLqzN3G5BHfj31lSIIk5mMcIuLK0u6D8N8ITt3+OvNvNNIeUD2A9op1swb9v8Y92RQ9WnVPQnIeHgRVZJnl3sLyr47ERsb keybox@global_key 2017-05-10 14:13:13.610:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@7e0b0338{/,file:///tmp/KeyBox-jetty/jetty/keybox/,AVAILABLE}{/tmp/KeyBox-jetty/jetty/keybox} 2017-05-10 14:13:13.628:INFO:oejus.SslContextFactory:main: x509=X509@51b1a8f6(jetty,h=[],w=[]) for SslContextFactory@2a389173(file:///tmp/KeyBox-jetty/jetty/etc/keystore,file:///tmp/KeyBox-jetty/jetty/etc/keyst ore)2017-05-10 14:13:13.660:INFO:oejs.AbstractConnector:main: Started ServerConnector@1fc76fc9{SSL,[ssl, http/1.1]}{0.0.0.0:8443} 2017-05-10 14:13:13.660:INFO:oejs.Server:main: Started @12100ms # 查看8443端口 $ ss -tnl | grep 8443 LISTEN 0 50 :::8443 :::* # keybox啟動腳本的使用方法 $ /usr/local/keybox/jetty/bin/jetty.sh Usage: jetty.sh [-d] {start|stop|run|restart|check|supervise} [ CONFIGS ... ]
三、訪問keybox
1、使用瀏覽器打開
2、輸入默認的用戶名admin,密碼changeme登錄
四、新建用戶并配置免密鑰ssh訪問
本次使用的是通過腳本配合ansible來新建和配置
1、安裝ansible并配置
$ yum install -y ansible $ vim /etc/ansible/hosts # 示例 [proxy] 192.168.1.201 [web] 192.168.1.202 192.168.1.203 [mysql] 192.168.1.204 192.168.1.205
2、配置root與ansible配置文件中的主機免密鑰ssh訪問,這里就不多贅述了,通過ssh-keygen與ssh-copy-id即可完成
3、在多臺主機上新建用戶密碼并免密鑰ssh登錄
# 新建用戶 $ vim user_add.sh for name in test{1..5} do ansible all -m user -a "name=$name generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa state=present group=java" done $ ./user_add.sh # 配置密碼 $ vim passwd_add.sh for i in test{1..5} do ansible all -m shell -a "echo '123456' | passwd --stdin $i" done $ ./passwd_add.sh # 免密鑰ssh配置 $ yum install -y expect $ vim ssh_add.sh for user in test{1..5} do pass='123456' for ip in `cat /etc/ansible/hosts | grep "^[^([|#)].*"`; do /usr/bin/expect << EOF set timeout 300 spawn ssh-copy-id -i /home/$user/.ssh/id_rsa.pub $user@$ip expect { "(yes/no)" {send "yes\r"; exp_continue} "password:" {send "$pass\r"} } expect eof EOF done done $ ./ssh_add.sh
五、將相關用戶與主機信息寫入keybox數據庫
1、將/usr/local/keybox/jetty/中的keybox文件夾復制到桌面
2、下載H2數據庫console(keybox使用的是H2數據庫):http://www.h3database.com/html/quickstart.html
3、連接數據庫
其中JDBC 1、URL:jdbc:h3:file:C:\Users\Administrator\Desktop\keybox\WEB-INF\classes\keydb\keybox;CIPHER=AES;
2、用戶名為默認的:keybox
3、密碼格式為"filepassword空格userpassword":filepwd 初始化時新建的密碼
4、進入數據庫
5、新建數據
主要需要新建數據的表有5個,分別是
·PROFILES:用戶空間 示例:INSERT INTO PROFILES (NM,DESC) VALUES ('test1','test1 space');
·SYSTEM:用戶和hosts的ssh信息 示例:INSERT INTO SYSTEM(DISPLAY_NM,USER,HOST,PORT,AUTHORIZED_KEYS,STATUS_CD) values ('proxy','test1','192.168.1.201',22,'/home/test1/.ssh/authorized_keys','SUCCESS');
·SYSTEM_MAP:PROFILE和SYSTEM通過ID進行關聯 示例:INSERT INTO SYSTEM_MAP(PROFILE_ID,SYSTEM_ID) VALUES (1,1);
·USERS:用戶信息,默認已有admin 示例:INSERT INTO USERS (USERNAME,USER_TYPE) VALUES ('test5','A');
·USER_MAP:PROFILE和USER通過ID進行關聯 示例:INSERT INTO USER_MAP (USER_ID,PROFILE_ID) VALUES (2,1);
六、配置數據并訪問
使用admin用戶登錄,配置test1-5的密碼,然后使用test1-5中的用戶登錄keybox后就可以使用了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。