티스토리 뷰

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 접속시에는 이전 유저의 환경변수가 그대로 남아 있는것을 확인할 수 있다. 





공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG more
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함