$ HOME 환경 변수는 어디에 설정되어 있습니까? 곳을 찾고

$ HOME 환경 변수가 설정된 곳을 찾고 있습니다. 내 마음에 로그인 후입니다.

Linux debian 2.6.32-5-686을 사용하고 있습니다.



답변

당신이 당신의 가정을 수정하려고하면 할 수 있습니다

export HOME=/home/...

쉘 또는 ~ / .profile 파일 및 / 또는 ~ / .bashrc (또는 적절한 로그인 쉘)에서.

(위의 코드는 bash와 데비안에서는 기본적으로 비슷한 쉘에서 작동합니다; 그렇지 않으면`setenv HOME $ HOME : / extra / path 할 것입니다. 다른 배포판에서는 csh와 같은 쉘을 생각합니다.)

편집 -그러나 이것은 아마도 그렇게하는 방법이 아닙니다. 다른 답변을 참조하십시오. 이 답변을 사용하지 마십시오.


답변

Linux에서 HOME환경 변수는 로그인 프로그램에 의해 설정됩니다.

  • 에 의해 login콘솔에 텔넷RLOGIN 세션
  • 으로 sshd SSH 연결을위한
  • 에 의해 gdm, kdm또는 xdm그래픽 세션.

답변

로그인 프로그램은 / etc / passwd의 값을 기반으로 쉘에서 exec를 호출하기 전에 (exec의 인수에 포함하여)이를 정렬합니다.


답변

다음을 실행하여이를 편집하십시오 usermod -d /home/whatever_dir whatever_user..

이것은 새로운 홈 디렉토리가 될 것입니다. Bash는 cd로그인시 그것에 접근하므로 존재하고 권한이 올바른지 확인하십시오. 또한, 대한 잊지 마세요 .bashrc, .profile, .xinitrc, 등; 홈 디렉토리에 없으면 읽을 수 없습니다.

보낸 사람 usermod:

Usage: usermod [options] LOGIN

Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                him/her from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account


답변

나는 파고 들었고 이것에 대한 대답은 약간 놀랍습니다. 다음 테스트 스크립트를 작성 chmod +x하십시오.

#!/bin/bash 
printf 'My home is: '
echo  ~ || echo 'nowhere'

우리는 그것을 실행 ./test.sh하고 볼 수 있습니다 :

내 집은 : / home / user

strace로 후드 아래를 들여다 보자.

$ strace ./test.sh |& grep '^open[a-z]*'

openat (AT_FDCWD, “/etc/ld.so.cache”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libtinfo.so.5”, O_RDONLY | O_CLOEXEC) = 3
openat ( AT_FDCWD, “/lib/x86_64-linux-gnu/libdl.so.2”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libc.so.6”, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “/ dev / tty”, O_RDWR | O_NONBLOCK) = 3
openat (AT_FDCWD, “/ usr / lib / locale / locale-archive”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/ usr / lib / x86_64-linux-gnu / gconv / gconv-modules.cache “, O_RDONLY) = 3

openat (AT_FDCWD,”./test.sh “, O_RDONLY) = 3

HOME, rc 파일 또는 passwd에 대한 언급이 없습니다. 깨끗한 환경에서 시도해 봅시다.

env -i bash
echo $HOME  #this will be blank since we cleared the env

예상대로 아무것도 아닙니다. 빈 환경에서 스크립트를 실행 해 봅시다.

env -i bash
./test.sh 

내 집은 : / home / user

흥미롭게도, 대본은 집으로 돌아갈 수 있습니다. 이제 추적하자.

strace ./test.sh |& grep '^open[a-z]*'

이제 우리는 본다 :

openat (AT_FDCWD, “/etc/ld.so.cache”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libtinfo.so.5”, O_RDONLY | O_CLOEXEC) = 3
openat ( AT_FDCWD, “/lib/x86_64-linux-gnu/libdl.so.2”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libc.so.6”, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “/ dev / tty”, O_RDWR | O_NONBLOCK) = 3
openat (AT_FDCWD, “/etc/nsswitch.conf”, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “/etc/ld.so. 캐시 “, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD,”/lib/x86_64-linux-gnu/libnss_compat.so.2 “, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD,”/etc/ld.so.cache ” , O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libnss_nis.so.2 “, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libnsl.so.1”, O_RDONLY | O_CLOEXEC) = 3

openat (AT_FDCWD, “/lib/x86_64-linux-gnu/libnss_files.so.2”, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “/ etc / passwd”, O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, “./test.sh”, O_RDONLY) = 3

흥미로운 선을 굵게 표시했습니다. 보시다시피, $HOME정의되지 않은 경우, 쉘은 로그인 또는 대화식 모드가 아닌 경우에도 쉘을 채우려 고 시도합니다.


답변