Enter password-free login
No need for third-party software such as Iterm and Zoc, alias (pure terminal) and shuttle (with UI) to log on to the target machine using the password (no manual input required)
Preparation Tools
Sshpass,shuttle
Password configuration file
Password file (clear text storage, if you consider strong security issues, please bypass)
Format: hostname (defined in system Hosts file), user, password, ssh_port
$ cat /Users/zhang/zhangsan/work/secure vm-001 root 123456 1122vm-002 root 123456 22
Script
- Core scripts
$ cat /Users/zhang/zhangsan/work/ssh.sh #!/bin/shWORK_DIR=$(dirname $0)cd $WORK_DIRHOST=$1;USER=$2;if [ "x${HOST}" == "x" -o "x${USER}" == "x" ]; then exit 2fiPASS_PORT=$(grep -E "^$HOST\s+$USER\s+" secure)PASS=$(echo $PASS_PORT | awk ‘{print $3}‘)PORT=$(echo $PASS_PORT | awk ‘{print $4}‘)if [ "x${PASS}" == "x" -o "x${PORT}" == "x" ]; then exit 2fiexec sshpass -p $PASS ssh -p $PORT [email protected]$HOST
The update logic script is stored to ~/.bash_profile, and each login will regenerate the required configuration files for alias and shuttle based on secure
Alias
After you add the following script in ~/.bash_profile, update the alias
while read LINEdoSSH_HOST=$(echo "$LINE" | awk ‘{print $1}‘)SSH_USER=$(echo "$LINE" | awk ‘{print $2}‘)alias "$SSH_HOST$SSH_USER"="sh /Users/zhang/zhangsan/work/ssh.sh $SSH_HOST $SSH_USER"done < /Users/zhang/zhangsan/work/secure
- Shuttle
Generate a Python script for shuttle configuration
$ cat /Users/zhang/zhangsan/work/shuttle.py import jsonshuttle = { "editor": "default", "launch_at_login": True, "terminal": "Terminal.app", "iTerm_version": "nightly", "default_theme": "Default", "open_in": "tab", "show_ssh_config_hosts": False, "ssh_config_ignore_hosts": [], "ssh_config_ignore_keywords": [], "hosts": []}with open("/Users/zhang/zhangsan/work/secure", "r") as f: while True: line = f.readline() if not line: break HOST_PORT = line.split() if len(HOST_PORT) >= 3: HOST, PORT = HOST_PORT[0], HOST_PORT[1] shuttle["hosts"].append({"cmd": "sh /Users/zhang/zhangsan/work/ssh.sh {HOST} {PORT}".format(HOST=HOST, PORT=PORT) , "name": "{HOST} {PORT}".format(HOST=HOST, PORT=PORT)})with open("/Users/zhang/.shuttle.json", "w") as f: json.dump(shuttle, f, indent=2)
Add python/users/zhang/zhangsan/work/shuttle.py to ~/.bash_profile, generate shuttle configuration file
Note
Mac Zoc is a simple and easy to use an SSH client, but has crashed several times (genuine will be better)
Reference links
Download Shuttle
Installing Sshpass
Mac terminal SSH client shuttle password free