본문 바로가기
Errors

[WSL] root계정으로만 로그인 되는 경우.

by ds31x 2023. 9. 19.

WSL로 ubuntu등을 설치할 때, 중간에 해당 배포판의 계정을 입력하라는 다음의 문구가 나온다.

Installing: Ubuntu 20.04 LTS
Ubuntu 20.04 LTS has been installed.
Launching Ubuntu 20.04 LTS...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:

위와 같이 new UNIX username:으로 사용할 계정 id를 입력하고 이후 passwd를 입력하면 정상적인 경우,

wsl을 시작시키면 해당 계정으로 로그인이 되어 시작된다.

 

문제는 위의 과정 등에서 입력을 안하고 종료 등을 한 경우,

해당 WSL의 배포판을 실행할 경우 root 계정으로 로그인이 된다.

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

생략...


This message is shown once a day. To disable it please create the
/root/.hushlogin file.
root@컴퓨터이름:현재경로#
  • 위에서 prompt를 보면 root@컴퓨터이름:현재경로root계정으로 로그인 됨을 알 수 있다.

다시 정상적으로 사용자 계정으로 로그인되도록 하려면,

우선 사용할 사용자 계정이 만들어져 있는지 /etc/passwd 파일 등을 통해 확인한다.

 

다음의 명령어를 root계정으로 수행할 경우 출력이 되면 계정이 있는 것임.

$ cat /etc/passwd |grep 대상_사용자_계정

만약 아무 출력이 나오지 않는다면 계정이 없는 것이므로 해당 사용자 계정을 추가한다.

# adduser dsaint31

adduser를 수행하면, 다음과 같이 dsaint31이라는 계정명의 사용자를 추가하게 된다.

# adduser dsaint31
Adding user `dsaint31' ...
Adding new group `dsaint31' (1000) ...
Adding new user `dsaint31' (1000) with group `dsaint31' ...
Creating home directory `/home/dsaint31' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for dsaint31
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y
  • 패스워드를 물어본다. 이 때 타이핑을 쳐도 보이지 않는게 정상임.
  • Full Name 등의 정보는 입력하지 않아도 상관없음.

계정 추가 이후, sudo 명령어를 통해 프로그램 설치 등이 가능하도록 새로 추가된 계정의 그룹을 sudo로 변경한다.

# usermod -a -G sudo 대상계정명

이후 groups 명령어로 해당 계정의 group이 sudo인지 확인한다.

# groups 대상계정
대상계정 : 대상계정 sudo

위를 통해 사용할 계정이 추가 완료되고 나면,

우선 wsl에서 나오고(exit),  WSL 시작시 기본 계정을 설정을 위해 다음 명령어로 설정해준다.
(Windows의 power shell 또는 cmd prompt에서 입력할 것.)

ubuntu2004.exe config --default-user 대상계정
  • wsl -l -v에서 배포판의 이름이 Ubuntu-20.04 인 경우, 명령어는 ubuntu2004.exe임.
  • 만약 Ubuntu-22.04인 경우, 명령어는 ubuntu2204.exe임.

이후 대상 배포판을 수행하면 정상적으로 해당 계정으로 로그인 된다.


참고자료

https://ds31x.tistory.com/67?authuser=0

 

[Env] WSL 기본 명령어 정리.

wsl 자체 관련 wsl update or rollback (wsl 자체에 대한) wsl --update # wsl version update wsl --update rollback # 이전 버전으로 상태 확인 wsl --status Help wsl --help Distribution 실행 관련 wsl로 default distribution 실행하기 bas

ds31x.tistory.com

https://devji.tistory.com/entry/Ubuntu-2004-%EC%82%AC%EC%9A%A9%EC%9E%90-%EC%B6%94%EA%B0%80-sudo-%EA%B6%8C%ED%95%9C-%EB%B6%80%EC%97%AC-adduser-usermod-userdel

 

Ubuntu 20.04 사용자 추가, sudo 권한 부여 (adduser, usermod, userdel)

admin 계정만으로 서버를 사용하는 것은 비밀번호의 노출 빈도를 높이게 되어 위험합니다. 별도의 계정을 생성 후 sudo 권한을 부여하여 사용할 수 있습니다. 사용자 추가 명령어는 useradd, adduser 두

devji.tistory.com

 

728x90