iterm2 Shell Integration
iterm2 是 MacOS 下最为流行的终端工具,其中的Shell Integration允许用户能够直接以拖拽、右键菜单的形式来在客户端和服务器之间传输文件。主要是替代不方便的 sftp 来实现 C/S 通信。
Tips
他的核心是通过 scp 命令来在服务器和客户端之间复制文件
安装
安装分为手动和自动安装:
Bash
# bash 下
curl -L https://iterm2.com/shell_integration/bash -o ~/.iterm2_shell_integration.bash
source ~/.iterm2_shell_integration.bash # 需要写入 .bash_profile 文件中
# zsh 下
curl -L https://iterm2.com/shell_integration/zsh -o ~/.iterm2_shell_integration.zsh
source ~/.iterm2_shell_integration.zsh # 需要写入 .zshrc 文件末尾
对于自动安装可以通过 Iterm2 -> Install Shell Integration
来自动安装,注意安装前需要先 ssh 到服务器上。
使用
对于上传,可以通过按下 Option 按键并拖拽文件到 Iterm2 界面来实现。对于下载可以直接点击 Iterm2 中对应的文件条目(通过 ls 输出)来下载。之后的下载进度能够在 Iterm2 菜单栏中的 Downloads Uploads
中查看。
第一次使用大多数时候会报错,这通常是因为我们没有设置好服务器地址和 hostname 导致的,可以点击文件的 Get Info
会得到下面的内容:
Text Only
Secure copy
User name: yangguodong
Host: debian.domain
File: /home/yangguodong/path/to/files.csv
其中错误的核心就是 Host 是错误的,他应该对应服务器的 Host 才对,但是它实际上对应了 debian.domain
了。这是因为我们在 /etc/hosts
中设置了他:
安装过 archlinux 的都知道,其中推荐设置本机 ip 地址到 [hostname].domain
上,但是前提内网实用。如果有公网的地址就需要填写其他内容。因此这里就需要填写到我们实际连接该服务器的 Host:Port
。
Tips
对应的实际上就是客户端 ~/.ssh/config
中针对该服务器的 Host 和 Port