티스토리 뷰
su 명령어 (change user ID or become super user) 사용시 '-' (hypen) 을 사용하는 경우와 그렇지 않은 경우가 항상 헷갈렸었는데 이 내용을 정리하고자 한다.
아래 스택오버플로우 페이지에 상세하게 설명되어 있다.
https://superuser.com/questions/453988/whats-the-difference-between-su-with-and-without-hyphen
hypen 을 사용하게 되면 아래와 같이 2가지 차이점이 있다.
The hyphen has two effects:
1) switches from the current directory to the home directory of the new user (e.g., to /root in the case of the root user) by logging in as that user
2) changes the environmental variables to those of the new user as dictated by their ~/.bashrc. That is, if the first argument to su is a hyphen, the current directory and environment will be changed to what would be expected if the new user had actually logged on to a new session (rather than just taking over an existing session).
1) 루트 유저또는 새로운 유저로 접속시 그 유저의 home 디렉토리로 자동 변경된다. 아래와 같이 su - 와 su 를 통해 root 유저로 로그인시 그 차이를 확인할 수 있다. su - 로 접속시에는 root 유저의 home 디렉토리인 " /root " 로 디렉토리가 변경 되었음을 확인할 수 있다. 반변 su 로 root 로그인시에는 이전 user 의 홈디렉토리가 변경되지 않았음을 확인할 수 있다.
su - 명령 적용시
su 명령으로 root 유저 변경시
2) 변경할 유저의 환경변수를 불러오므로 새로 로그인한것과 같은 효과를 가진다. 아래 그림처럼 이전 유저에서 정의된 환경변수는 su - 로 root 접속시에는 불러올 수 없다. 왜냐하면 root 의 환경변수에는 MY_VAR 는 정의되어 있지 않기 때문이다. 즉, root 의 환경변수로 환경변수들이 대체 되므로 이전 유저의 환경변수는 사용할 수 없다. 반면 su 로 root 접속시에는 이전 유저의 환경변수가 그대로 남아 있는것을 확인할 수 있다.
'리눅스 > 리눅스 명령어 및 기타' 카테고리의 다른 글
[리눅스명령어] ls 명령 팁정리 (0) | 2018.03.12 |
---|---|
리눅스커널 스터디 2013.09.14 정리 (0) | 2013.09.14 |
module 에서의 sys_* (시스템 콜) 함수호출?? (0) | 2013.08.14 |
리눅스 커널(3.9.3 기준)에 시스템 콜 추가하기 .. (0) | 2013.06.29 |
모듈 따로 컴파일하기(Kbuild and module compile) (0) | 2013.06.12 |