Skip to content

Split View: Linux su su - 명령어 차이점

|

Linux su su - 명령어 차이점

Overview

리눅스를 사용하다보면, 현재 계정을 로그아웃하지 않고, superuser인 root로 로그인해야할 때가 있습니다. 이 때 사용하는 명령어가 su root 또는 su - root 입니다. 기본적으로 user name을 입력하지 않으면 su 명령어는 root로 로그인하게 됩니다. 유저를 변경하는, su 명령어와 su - 의 차이점을 알아봅니다.

su (Switch User) 명령어

shell에서 su 명령어를 입력하면 현재의 환경변수를 그대로 유지한 채로 root 사용자로 변경합니다.

su

su - (Switch User) 명령어

shell에서 su - 를 입력하면 root로 로그인 하며, directory도 root의 home으로 변경하게 됩니다. 기존 환경변수는 사라지게 됩니다.

sh -

이 경우 root 계정 하위에 있는 ~/.bash_profile 또는 ~/.bashrc 에 정의된 환경변수를 불러오게 됩니다.

정리하자면, susu - 명령어는 dash 이전 유저의 환경변수를 불러오느냐 마느냐의 차이입니다.
이상으로 user 변경을 하는 Linux 명령어에 대해 알아보는 알아보는 이번 포스팅을 마치도록 하겠습니다. 감사합니다.

Difference Between Linux su and su - Commands

Overview

When using Linux, there are times when you need to log in as the superuser root without logging out of the current account. The commands used for this are su root or su - root. By default, if no user name is specified, the su command logs in as root. Let's look at the difference between the su and su - commands for switching users.

su (Switch User) Command

When you enter the su command in the shell, it switches to the root user while keeping the current environment variables.

su

su - (Switch User) Command

When you enter su - in the shell, it logs in as root and also changes the directory to root's home directory. The previous environment variables are discarded.

sh -

In this case, the environment variables defined in ~/.bash_profile or ~/.bashrc under the root account are loaded.

In summary, the difference between the su and su - commands is whether or not the previous user's environment variables are loaded before the dash. This concludes the post about the Linux commands for switching users. Thank you.

Quiz

Q1: What is the main topic covered in "Difference Between Linux su and su - Commands"?

Learn the difference between the su and su - commands in Linux.

Q2: What are the key takeaways from this article? Learn the difference between the su and su - commands in Linux.

Q3: How can the concepts in this article be applied in practice? Consider the practical examples and patterns discussed throughout the post.