MacOS使用iTerm2连接服务器

时间:2025-03-30 09:57:45

MacOS使用iTerm2连接服务器

# 此处脚本创建在/Users/narcos/Documents/iterm目录下
cd /Users/narcos/Documents/iterm
touch 
vi 
chmod 777 
  • 1
  • 2
  • 3
  • 4
  • 5
#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

解释:

[lindex $argv 0]:端口

[lindex $argv 1]:username

[lindex $argv 2]:host

[lindex $argv 3]:password

软件iTerm2中

profiles -> Open profiles (对应快捷键command + o)

选择Edit Profiles…

新建一个profile,在General中

Name:对应的服务器名

Command:选择LoginShell

Send text at start :/Users/narcos/Documents/iterm/ 对应的端口(一般为22) 对应的服务器账号(一般为root) 对应的服务器ip 对应的服务器密码

如果要在iterm中完成上传和下载文件功能,可参考我的github
/beastmouth/iterm2-zmodem