<br>
# Introduction
iTerm2에서 SSH로 접속한 호스트명을 탭에 표시하는 방법은 다음과 같습니다:
<br>
# Steps
### 1. SSH 설정 파일 수정:
`~/.ssh/config` 파일을 열고 다음 내용을 추가합니다:
```
Host *
PermitLocalCommand yes
LocalCommand printf "\033]0;%h\007"
```
이 설정은 모든 SSH 연결에 대해 로컬 명령 실행을 허용하고, 연결된 호스트명을 터미널 제목으로 설정합니다.
### 2. iTerm2 프로필 설정:
iTerm2 > Preferences > Profiles로 이동한 후, 사용 중인 프로필을 선택합니다. 'Terminal' 탭에서 'Set locale variables automatically' 옵션을 체크합니다.
### 3. 쉘 설정 수정:
사용 중인 쉘의 설정 파일(예: `~/.bashrc`, `~/.zshrc`)에 다음 함수를 추가합니다:
```bash
ssh() {
if [[ -n "$TMUX" ]]; then
tmux rename-window "$(echo $* | cut -d . -f 1)"
command ssh "$@"
tmux set-window-option automatic-rename "on" 1>/dev/null
else
command ssh "$@"
fi
}
```
이 설정을 적용하면 SSH로 접속할 때마다 iTerm2 탭에 연결된 호스트명이 표시됩니다.
<br>
<br>
# References
Claudi AI
<br>
# Links
[[_MOC_2_Server]]
<br>