在MAC上还没发现xshell一样的终端工具。不过mac的终端命令,可以写好多脚本来管理。
首先想到的就是把服务器IP及密码使用shell管理起来,以便下次登录的时候不用在重新输入,或者只输入代号就行。但是在写的时候发现ssh 是不支持密码参数的,不过找到sshpass 这个是可以的。
首先安装sshpass
cmd:~ dongjunjie$ brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb ######################################################################## 100.0% xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Error: sshpass cannot be built with any available compilers. Install GNU's GCC brew install gcc cmd:~ dongjunjie$ brew install gcc ==> Installing dependencies for gcc: gmp, isl, mpfr, libmpc ==> Installing gcc dependency: gmp xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun Error: Failure while executing: git config --local --replace-all homebrew.private true cmd:~ dongjunjie$ xcode-select --install xcode-select: note: install requested for command line developer tools cmd:~ dongjunjie$ brew install gcc ==> Installing dependencies for gcc: gmp, isl, mpfr, libmpc ==> Installing gcc dependency: gmp ==> Downloading https://homebrew.bintray.com/bottles/gmp-6.1.2_2.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring gmp-6.1.2_2.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/gmp/6.1.2_2: 18 files, 3.1MB ==> Installing gcc dependency: isl ==> Downloading https://homebrew.bintray.com/bottles/isl-0.19.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring isl-0.19.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/isl/0.19: 66 files, 3.8MB ==> Installing gcc dependency: mpfr ==> Downloading https://homebrew.bintray.com/bottles/mpfr-4.0.1.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring mpfr-4.0.1.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/mpfr/4.0.1: 28 files, 4.6MB ==> Installing gcc dependency: libmpc ==> Downloading https://homebrew.bintray.com/bottles/libmpc-1.1.0.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring libmpc-1.1.0.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/libmpc/1.1.0: 12 files, 353.8KB ==> Installing gcc ==> Downloading https://homebrew.bintray.com/bottles/gcc-8.1.0.high_sierra.bottle.1.tar.gz ######################################################################## 100.0% ==> Pouring gcc-8.1.0.high_sierra.bottle.1.tar.gz 🍺 /usr/local/Cellar/gcc/8.1.0: 1,495 files, 336.1MB cmd:~ dongjunjie$ brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb ######################################################################## 100.0% ==> Downloading http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz ==> Downloading from https://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz ######################################################################## 100.0% ==> ./configure --prefix=/usr/local/Cellar/sshpass/1.06 ==> make install 🍺 /usr/local/Cellar/sshpass/1.06: 9 files, 41.6KB, built in 18 seconds cmd:~ dongjunjie$ sshpass Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters -f filename Take password to use from file -d number Use number as file descriptor for getting password -p password Provide password as argument (security unwise) -e Password is passed as env-var "SSHPASS" With no parameters - password will be taken from stdin -P prompt Which string should sshpass search for to detect a password prompt -v Be verbose about what you're doing -h Show help (this screen) -V Print version information At most one of -f, -d, -p or -e should be used
其中有一个小插曲
安装sshpass 提升没有gcc 安装gcc 有出现
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun 错误
解决办法:
终端输入:xcode-select --install 系统弹出下载xcode,点击确认,下载完成后即可真(可能下载xcode有关插件)。出现这个错误猜想可能是因为我之前安装过xcode又卸载有关。
然后开始写脚本进行,之后便比较随意了
#!/bin/sh sshpass -p "pwd" ssh dongjunjie@10.60.**.**
可以参考 http://tinyhema.iteye.com/blog/2093795