Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

Windows 10 - bash 실행 시 시작 디렉터리 자동 변경

bash 처음 켜면 경로가 /home/[username]으로 설정되어 있는데요.

TestUser@MYPC:~$ pwd
/home/TestUser
TestUser@MYPC:~$

이걸 바꾸고 싶다는 질문이 들어와서 잠깐 찾아봤습니다. 뭐랄까, 도스(DOS) 시절 같으면 autoexec.bat에서 "cd ...[path]..." 명령어를 등록해 주면 DOS Shell 시작하자마자 특정 폴더로 이동하게 할 수 있는데... bash는 리눅스이므로 그에 따른 별도의 절차를 따르면 됩니다. 이는 다음의 문서에 잘 나와 있습니다.

Shell initialization files
; http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html

위의 문서에 보면 다음의 다양한 설정 파일에 대한 소개가 나옵니다.

  • /etc/profile: 시스템 전역 설정
  • /etc/profile.d: 특정 프로그램에 대한 시스템 전역 설정
  • /etc/bashrc: Bash Shell 전용 설정 파일
  • ~/.bash_profile: 사용자 전용 설정 파일
  • ~/.bash_login: 사용자 로그인 시에만 실행되는 설정 파일
  • ~/.profile: 2개의 설정 파일(~/.bash_profile, ~/.bash_login)이 없는 경우에 적용되는 설정 파일
  • ~/.bashrc: 로그인이 없는 환경에서도 참조되는 사용자 설정 파일

ls -a 명령을 내려보면 이미 ~/.bashrc 파일과 ~/.profile이 있는 것을 볼 수 있습니다.

TestUser@MYPC:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .profile
TestUser@MYPC:~$

테스트해보면 윈도우의 bash shell을 실행하면 ~/.profile은 로드되지 않고 ~/.bashrc는 로드됩니다.

아마도 ~/.profile은 해당 파일에 포함된 주석(executed by the command interpreter for login shells)에 따라 명시적으로 로그인하는 경우에만 실행되는 듯합니다. (~/.bashrc 파일은 주석에서 "executed by bash(1) for non-login shells."라고 명시하고 있습니다.)

그럼, 이제 답이 나왔군요. vi든 nano든 편집기를 이용해 .bashrc 파일의 마지막에 cd ...[경로]...를 입력해 두면 됩니다.

TestUser@MYPC:~$ nano .bashrc
TestUser@MYPC:~$ cat .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

...[생략]...

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

cd /mnt/c/temp

이후 bash shell을 시작하면 폴더가 윈도우의 "c:\temp"에 해당하는 경로로 시작합니다.

TestUser@MYPC:/mnt/c/temp$ pwd
/mnt/c/temp
TestUser@MYPC:/mnt/c/temp$




참고로, cmd.exe에서 bash를 실행하는 경우 0x80070002 오류가 발생하면서 실행이 안되는 경우가 있습니다.

c:>bash
Error: 0x80070002

다음의 글을 보시면 해답이 나오는데요.

Problems reinstalling Bash on Ubuntu on Windows Error: 0x80070002 
; http://answers.microsoft.com/en-us/insider/forum/insider_wintp-insider_install/problems-reinstalling-bash-on-ubuntu-on-windows/bb32e0a5-e711-410b-b28b-ebc561d5b4d8?auth=1

제 경우에는 위의 글에서 소개하는 첫 번째 방법인 "Use legacy console" 옵션은 통하지 않았습니다. 대신 관리자 콘솔을 띄운 후 다음과 같이 "lxrun"을 이용해 "Windows Subsystem for Linux"를 재설치하는 것으로 해결되었습니다.

lxrun /uninstall /full
lxrun /install /y




Bash Shell을 실행했는데 사용자 폴더가 다음과 같이 root로 되는 경우가 있습니다.

root@MYPC:~# pwd
/root
root@MYPC:~#

이건, bash shell을 처음 실행 시 기본 사용자 설정을 하지 않았거나, 또는 lxrun을 이용해 "Windows Subsystem for Linux"를 설치한 경우 그렇게 됩니다.

괜찮습니다. ^^ 다음의 글에 따라,

How to Change Your User Account in Windows 10’s Ubuntu Bash Shell
; http://www.howtogeek.com/261417/how-to-change-your-user-account-in-windows-10s-ubuntu-bash-shell/

cmd.exe 창을 띄워 기본 사용자를 설정하거나,

C:\>lxrun /setdefaultuser TestUser
새 UNIX 암호 입력:
새 UNIX 암호 재입력:
passwd: password updated successfully
Default UNIX user set to: TestUser

다시 root 사용자 계정으로 설정할 수도 있습니다.

C:\>lxrun /setdefaultuser root
Found UNIX user: root
Default UNIX user set to: root

현재 사용자의 암호를 변경하고 싶다면 bash shell 내에서 passwd 명령어로 가능합니다.

TestUser@MYPC:~$ passwd
TestUser에 대한 암호 변경 중
(현재) UNIX 암호:
새 UNIX 암호 입력:
새 UNIX 암호 재입력:
passwd: password updated successfully
TestUser@MYPC:~$

마지막으로 bash shell 내에서 사용자 인증을 변경하고 싶다면 "su [username]" 명령을 사용하면 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 12/13/2019]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...
NoWriterDateCnt.TitleFile(s)
12124정성태1/23/202010375VS.NET IDE: 140. IDE1006 - Naming rule violation: These words must begin with upper case characters: ...
12123정성태1/23/202011843웹: 39. Google Analytics - gtag 함수를 이용해 페이지 URL 수정 및 별도의 이벤트 생성 방법 [2]
12122정성태1/20/20208845.NET Framework: 879. C/C++의 UNREFERENCED_PARAMETER 매크로를 C#에서 우회하는 방법(IDE0060 - Remove unused parameter '...')파일 다운로드1
12121정성태1/20/20209360VS.NET IDE: 139. Visual Studio - Error List: "Could not find schema information for the ..."파일 다운로드1
12120정성태1/19/202010820.NET Framework: 878. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 네 번째 이야기(IL 코드로 직접 구현)파일 다운로드1
12119정성태1/17/202010871디버깅 기술: 160. Windbg 확장 DLL 만들기 (3) - C#으로 만드는 방법
12118정성태1/17/202011488개발 환경 구성: 466. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 세 번째 이야기 [1]
12117정성태1/15/202010519디버깅 기술: 159. C# - 디버깅 중인 프로세스를 강제로 다른 디버거에서 연결하는 방법파일 다운로드1
12116정성태1/15/202010996디버깅 기술: 158. Visual Studio로 디버깅 시 sos.dll 확장 명령어를 (비롯한 windbg의 다양한 기능을) 수행하는 방법
12115정성태1/14/202010754디버깅 기술: 157. C# - PEB.ProcessHeap을 이용해 디버깅 중인지 확인하는 방법파일 다운로드1
12114정성태1/13/202012596디버깅 기술: 156. C# - PDB 파일로부터 심벌(Symbol) 및 타입(Type) 정보 열거 [1]파일 다운로드3
12113정성태1/12/202013228오류 유형: 590. Visual C++ 빌드 오류 - fatal error LNK1104: cannot open file 'atls.lib' [1]
12112정성태1/12/20209835오류 유형: 589. PowerShell - 원격 Invoke-Command 실행 시 "WinRM cannot complete the operation" 오류 발생
12111정성태1/12/202013070디버깅 기술: 155. C# - KernelMemoryIO 드라이버를 이용해 실행 프로그램을 숨기는 방법(DKOM: Direct Kernel Object Modification) [16]파일 다운로드1
12110정성태1/11/202011625디버깅 기술: 154. Patch Guard로 인해 블루 스크린(BSOD)가 발생하는 사례 [5]파일 다운로드1
12109정성태1/10/20209561오류 유형: 588. Driver 프로젝트 빌드 오류 - Inf2Cat error -2: "Inf2Cat, signability test failed."
12108정성태1/10/20209603오류 유형: 587. Kernel Driver 시작 시 127(The specified procedure could not be found.) 오류 메시지 발생
12107정성태1/10/202010569.NET Framework: 877. C# - 프로세스의 모든 핸들을 열람 - 두 번째 이야기
12106정성태1/8/202011948VC++: 136. C++ - OSR Driver Loader와 같은 Legacy 커널 드라이버 설치 프로그램 제작 [1]
12105정성태1/8/202010620디버깅 기술: 153. C# - PEB를 조작해 로드된 DLL을 숨기는 방법
12104정성태1/7/202011344DDK: 9. 커널 메모리를 읽고 쓰는 NT Legacy driver와 C# 클라이언트 프로그램 [4]
12103정성태1/7/202014010DDK: 8. Visual Studio 2019 + WDK Legacy Driver 제작- Hello World 예제 [1]파일 다운로드2
12102정성태1/6/202011653디버깅 기술: 152. User 권한(Ring 3)의 프로그램에서 _ETHREAD 주소(및 커널 메모리를 읽을 수 있다면 _EPROCESS 주소) 구하는 방법
12101정성태1/5/202011028.NET Framework: 876. C# - PEB(Process Environment Block)를 통해 로드된 모듈 목록 열람
12100정성태1/3/20209065.NET Framework: 875. .NET 3.5 이하에서 IntPtr.Add 사용
12099정성태1/3/202011342디버깅 기술: 151. Windows 10 - Process Explorer로 확인한 Handle 정보를 windbg에서 조회 [1]
... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...