
[codex] SSH 접속 시 codex command not found
문제 상황
Windows에서 PuTTY로 Ubuntu 서버에 SSH 접속했더니
분명 서버에 설치해둔 nvm, codex가 아래처럼 안 잡힌다.
nvm: command not found
codex: command not found
로컬 터미널에서는 되는데,
SSH로 접속했을 때만 안 되는 상황.
원인
SSH 접속은 대부분 login shell로 동작한다.
Bash는 쉘 종류에 따라 읽는 설정 파일이 다르다.
~/.bashrc→ interactive non-login shell~/.profile또는~/.bash_profile→ login shell (SSH)
즉, nvm 로딩을 .bashrc에 넣어둔 경우
SSH login shell에서는 .bashrc가 자동으로 로드되지 않아
nvm미로딩- nvm 기반 node/npm 경로 미적용
codex경로 미적용- 결과적으로
command not found발생
해결 방법 (바로 적용)
핵심은 login shell에서도 .bashrc를 읽게 만드는 것이다.
~/.bash_profile 생성 또는 수정
vi ~/.bash_profile
아래 내용을 그대로 넣는다.
# Always load .bashrc for interactive bash shells (including SSH)
if [ -n "$BASH_VERSION" ] && [[ $- == *i* ]]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
저장 후 적용:
source ~/.bash_profile
SSH 재접속
PuTTY 세션을 끊고 다시 접속한다.
이제 SSH에서도:
command -v nvm
command -v codex
정상 경로가 출력된다.
정리
원인은 단순하지만,
SSH + nvm + CLI 도구(codex, node, npm 등)를 같이 쓰면 자주 겪는 문제다.
~/.bash_profile에서 .bashrc를 로드하도록 설정하면
이 문제는 영구적으로 해결된다.
끝 :)
0 댓글