KeepassX结合SecureCRT登录
以下配置实现:在KeepassX中双击一主机的"网址"部份,自动在SecureCRT的一个标签页中登录主机,将不用再输入帐号密码等信息。
SecureCRT
- ssh
把keepass中的key的url项改成如下形式:
# Windows: cmd://"D:\tools\SecureCRTPortable\App\SecureCRT\SecureCRT.exe" /N {TITLE} /L {USERNAME} /PASSWORD {PASSWORD} /T /P 22 {TITLE} # MacOS: cmd:///Applications/SecureCRT.app/Contents/MacOS/SecureCRT /N {TITLE} /L {USERNAME} /PASSWORD {PASSWORD} /T /P 22 {TITLE}
CRT的绝对路径是C:\SecureCRT\SecureCRT.exe,entry的title就是主机名(或IP地址),端口是22,USERNAME是用户(root或者是其他的用户名)。
详细说明可以查看crt的帮助文档的Using the Software--》Command-Line Options--》Table of Protocol-Specific Command-Line Options部分。
Windows
用批处理将以上命令包装一下,简化KeepassX里的设置,又可方便统一进行入口参数检查和调整、以及更换其他ssh工具。放到C:\windows目录下,方便直接调用。
在KeepassX的URL项设置为:cmd://ssh.cmd {TITLE} {USERNAME} {PASSWORD} 22
。
注意:KeepassX的标题要填写成IP地址。
另外,因KeepassX不把windows下的转义符^
当作特殊字符,若密码中包含^
字符,会因传参数时未加双引号而丢失^
符,造成登录失败。
-
C:\Windows\ssh.cmd
@ECHO OFF setlocal enabledelayedexpansion @REM C:\Windows\ssh.cmd @REM KeepassXURL: cmd://ssh.cmd {TITLE} {USERNAME} {PASSWORD} SSHPort SET SSHTOOL=SecureCRT @REM SET SSHTOOL=FileZilla @REM SET SSHTOOL=PuTTY @REM SET SSHTOOL=MobaXterm SET SecureCRTBIN="D:\tools\SecureCRTPortable\App\SecureCRT\SecureCRT.exe" SET FileZillaBIN="d:\tools\FileZilla\filezilla.exe" SET PuTTYBIN="D:\tools\putty\putty.exe" SET MobaXtermBIN="D:\tools\MobaXterm\MobaXterm.exe" SET SSHFIREWALL=PX2223 @REM SET SSHFIREWALL= @REM ------------------------------------------------------------------------------- SET HOST=%1 SET USER=%2 SET PW=%3 SET PORT=%4 IF "%HOST%" == "" GOTO HELP IF "%USER%" == "" GOTO HELP IF "%PW%" == "" GOTO HELP IF "%PORT%" == "" SET PORT=22 @REM IF "%HOST:~0,10%" == "172.16.33." SET SSHFIREWALL=PX2223 IF "%HOST:~0,7%" == "10.224." SET SSHFIREWALL= @REM IF "%HOST:~0,5%" == "172.1" SET SSHFIREWALL= IF "%SSHTOOL%" == "SecureCRT" GOTO SecureCRT IF "%SSHTOOL%" == "FileZilla" GOTO FileZilla IF "%SSHTOOL%" == "PuTTY" GOTO PuTTY IF "%SSHTOOL%" == "MobaXterm" GOTO MobaXterm GOTO END :SecureCRT @REM SecureCRT.exe /N {TITLE} /L {USERNAME} /PASSWORD {PASSWORD} /T /P 22 /FIREWALL 2223 {TITLE} START "" %SecureCRTBIN% /N %HOST% /FIREWALL=%SSHFIREWALL% /L %USER% /PASSWORD %PW% /T /P %PORT% %HOST% GOTO END :FileZilla START "" %FileZillaBIN% "sftp://%USER%:%PW%@%HOST%:%PORT%" GOTO END :PuTTY SET PuTTYSession= IF "%SSHFIREWALL%" NEQ "" SET PuTTYSession=-load %SSHFIREWALL% START "" %PuTTYBIN% -ssh -C %PuTTYSession% -l %USER% -pw %PW% -P %PORT% %HOST% GOTO END :MobaXterm @REM cmd://"MobaXterm.exe" -newtab "sshpass -p '{PASSWORD}' ssh {USERNAME}@{S:IP}" START "" %MobaXtermBIN% -newtab "sshpass -p '%PW%' ssh %USER%@%HOST%" GOTO END :HELP ECHO Usage: ssh.cmd HOST USER PASSWD GOTO END :END @REM PAUSE
- sftp的url
cmd://"C:\SecureCRT\SecureFX.exe" sftp://{USERNAME}:{PASSWORD}@{TITLE}
如果使用Keepass 2.0以上版本,则可以设置自定义属性。
MacOS
-
/usr/bin/ssh.cmd
#!/bin/sh #/usr/bin/ssh.cmd # KeepassX中网址URL设置方式: # cmd://ssh.cmd {TITLE} {USERNAME} {PASSWORD} SSHPort # 若不能正常执行,采用在KeepassX设置-高级中"自定义浏览器命令"的方式,URL中不要cmd://前缀 # ssh.cmd {TITLE} {USERNAME} {PASSWORD} SSHPort SSHTOOL=SecureCRT #SSHTOOL=FileZilla #SSHTOOL=PuTTY SecureCRTBIN="/Applications/SecureCRT.app/Contents/MacOS/SecureCRT" FileZillaBIN="Todo" PuTTYBIN="Todo" #SSHFIREWALL=PX2223 SSHFIREWALL= # ------------------------------------------------------------------------------- LogFile=~/$(basename $0).log exec 1>>"$LogFile" exec 2>&1 echo "$1"|grep "http" >/dev/null if [ "$?" = "0" ];then line=$(echo "$1"|sed -e 's/%20/ /g' -e 's;http://ssh.cmd ;;g') HOST=$(echo "$line"|awk '{print $1}') USER=$(echo "$line"|awk '{print $2}') PW=$(echo "$line"|awk '{print $3}') PORT=$(echo "$line"|awk '{print $4}') else HOST=$1 USER=$2 PW=$3 PORT=$4 fi Usage(){ echo "Usage:" echo "ssh.cmd HOST USER PASSWD" #echo "HOST=$HOST,USER=$USER,PW=$PW,PORT=$PORT" exit 1 } [ -z "$HOST" -o -z "$USER" -o -z "$PW" ] && Usage [ -z "$PORT" ] && PORT=22 echo "$HOST"|grep "^10.224." > /dev/null;[ "$?" = "0" ] && SSHFIREWALL= case "$SSHTOOL" in SecureCRT) #SecureCRT.exe /N {TITLE} /L {USERNAME} /PASSWORD {PASSWORD} /T /P 22 /FIREWALL PX2223 {TITLE} $SecureCRTBIN /N $HOST /FIREWALL=$SSHFIREWALL /L $USER /PASSWORD $PW /T /P $PORT $HOST > /dev/null 2>&1 & ;; FileZilla) $FileZillaBIN "sftp://$USER:$PW@$HOST:$PORT" >/dev/null 2>&1 & ;; PuTTY) PuTTYSession= [ -n "$SSHFIREWALL" ] && PuTTYSession="-load $SSHFIREWALL" $PuTTYBIN -ssh -C $PuTTYSession -l $USER -pw $PW -P $PORT $HOST >/dev/null 2>&1 ;; *) Usage ;; esac exit $?
CygWin
需要另外用except或pexcept写自动登录脚本才能完成自动登录。
# 先开一个终端,并运行以下命令开启sesssion screen -S ssh # 在keepassX中设置如下URL项: cmd://C:\cygwin\bin\bash.exe -c "/usr/bin/screen -dr -S ssh -X screen -t {TITLE} ssh {USERNAME}@{TITLE}"
调用putty
cmd://putty.exe -ssh {TITLE} -l {USERNAME} -pw {PASSWORD}
Linux桌面:gnome-terminal
-
需安装expect包:
# Ubuntu apt-get install expect # CentOS yum install expect
-
KeepassX网址设置如下内容:
cmd:///usr/bin/gnome-terminal -e "/usr/bin/expect -c 'spawn ssh {USERNAME}@{TITLE}; expect password:; send {PASSWORD}\r; interact >'"