![]() | 1 Mutoo 2014-08-07 20:45:30 +08:00 ![]() 1) 把 ip 加到 hosts 1.2.3.4 a 5.6.7.8 b 然后 ssh a / ssh b 2) 用 alias alias cOnna="ssh 1.2.3.4" |
![]() | 2 strak47 2014-08-07 20:51:04 +08:00 ![]() |
3 Busy 2014-08-07 20:54:59 +08:00 ![]() 可以写个脚本 case $num in 1) command ;; 2) command ;; ...... esac |
![]() | 4 clino 2014-08-07 20:55:34 +08:00 via Android ![]() 随便用python shell之类的写几行就出来了 当然针对楼主ssh的场合,在 .ssh/config里配置host就行了 |
![]() | 5 Tink PRO ![]() alias |
10 Busy 2014-08-07 21:22:09 +08:00 ![]() .ssh/config Host name IdentityFile ~/.ssh/yourkey HostName ip port port User remote-user 随后直接 ssh name |
11 xuxu 2014-08-07 21:28:26 +08:00 ![]() 写个可以接受参数的脚本,去掉后缀ln到PATH执行路径下。 |
13 sampeng 2014-08-07 22:33:12 +08:00 发慢了。。这种办法还能直接免密码登陆。。 |
![]() | 14 leavic 2014-08-07 23:06:12 +08:00 明显alias啊 |
![]() | 15 SoloCompany 2014-08-07 23:34:49 +08:00 .bash_profile conn() { local host case "$1” in ‘a’) host=1.2.3.4 ;; ‘b’) host=5.6.7.8 ;; ‘*’) echo 'conn what?' ;; esac shift 1 ssh $host “$@" } |
![]() | 16 kodango 2014-08-08 00:00:51 +08:00 ![]() 将以下内容添加到~/.bash_profile文件中: # Auto complete ssh server defined in ~/.ssh/config #complete -W "$(awk '/^Host/{if ($2!="*") print $2}' ~/.ssh/config)" ssh # Define ssh alias for server defined in ~/.ssh/config for host in $(awk '/^Host/{if ($2!="*") print $2}' ~/.ssh/config); do alias $host="ssh $host" done 然后 source ~/.bash_profile或者重新登录 shell,直接键入服务器别名,例如test,来ssh到相应的机器。 http://kodango.com/manage-ssh-connectiions |
![]() | 17 dingyaguang117 2014-08-08 00:49:56 +08:00 via iPad ssh-copy-id alias 我现在都sshxx直接登录 |
![]() | 18 tonitech 2014-08-08 01:07:31 +08:00 你到/etc/profile里面设置 alias cOnna="ssh 1.2.3.4" alias cOnnb="ssh 5.6.7.8" |
![]() | 19 caonan 2014-08-08 09:37:19 +08:00 10 楼正解。 |
![]() | 20 Liang OP @Havee 已通过该方法实现!3Q @xuu @sampeng @leavic @SoloCompany @kodango @dingyaguang117 @tonitech @caonan 3Q,很热心! |
![]() | 21 bjzhush 2014-08-08 11:29:39 +08:00 alias |
![]() | 22 huangyan9188 2014-08-08 15:44:20 +08:00 linux 的命令本身就是跑全局的程序 这些程序一般放在/usr/bin /usr/sbin 或者是环境变指定的文件夹下面,然后输入程序名(也就是指令)全局的来执行就好了 因此楼主只需要写一个程序放在全局路径下就ok了 怎么实现都可以,楼上诸位大神已经给出了脚本代码 |