Yanıtlar:
HOME'unuzu değiştirmeye çalışıyorsanız,
export HOME=/home/...
kabuğunuzda veya ~ / .profile dosyanızda ve / veya ~ / .bashrc (veya uygun giriş kabuğunda).
(Yukarıdaki kod Debian'da varsayılan olan bash ve benzer kabuklar için çalışacaktır; aksi takdirde `setenv HOME $ HOME: / extra / path Diğer dağıtımlardaki csh benzeri kabuklarda düşünüyorum.)
edit - Ancak bu muhtemelen bunu yapmak için bir yol değildir. Diğer cevaplara bakın. Bu cevabı kullanmayın.
Oturum açma programı, / etc / passwd içindeki değere dayalı olarak, kabukta exec çağırmadan önce (exec değişkenlerine ekleyerek) düzenler.
Çalıştırarak bu düzenleme: usermod -d /home/whatever_dir whatever_user.
Bunun (tabii ki) yeni giriş dizini olacağını lütfen unutmayın. Bash girişte cdbunu yapar, bu yüzden var olduğundan ve izinlerin doğru olduğundan emin olun. Buna ek olarak, unutma .bashrc, .profile, .xinitrcvb; ana dizinde bulunmuyorlarsa okunmazlar.
Gönderen 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
Biraz kazma yaptım ve bunun cevabı biraz şaşırtıcı. Aşağıdaki test komut dosyasını alın chmod +x:
#!/bin/bash
printf 'My home is: '
echo ~ || echo 'nowhere'
Birlikte çalıştırabilir ./test.shve görebiliriz:
Evim: / home / user
Strace ile kaputun altına bir göz atalım.
$ 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
açık (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 / yerel / yerel ayar-arşiv", O_RDONLY | O_CLOEXEC) = 3
openat (AT_FDCWD, "/ usr lib / x86_64-linux-gnu / gconv / gconv-modules.cache ", O_RDONLY) = 3
açık (AT_FDCWD," ./test.sh ", O_RDONLY) = 3
HOME, rc dosyaları veya passwd'den bahsetmiyorum. Temiz bir env ile deneyelim:
env -i bash
echo $HOME #this will be blank since we cleared the env
Beklendiği gibi bir şey yok. Komut dosyasını boş env'de çalıştıralım.
env -i bash
./test.sh
Evim: / home / user
İlginç, senaryo eve dönebiliyor. Şimdi izleyelim.
strace ./test.sh |& grep '^open[a-z]*'
Şimdi görüyoruz:
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
açık (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, "/etcld/ld.so./ önbellek ", 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
açık (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
açık (AT_FDCWD, "/ etc / passwd", O_RDONLY | O_CLOEXEC) = 3
açık (AT_FDCWD, "./test.sh", O_RDONLY) = 3
İlginç çizgileri cesaretlendirdim. Gördüğümüz gibi, $HOMEtanımlanmadığında, kabuğun giriş veya etkileşimli modda olmasa bile doldurmaya çalışacağı görülüyor .
$HOMEile$PATH. Birden fazla yol bulunması$HOME(tüm değerin tek bir yol adı olarak ele alınacağı) veya çoğu durumda$HOMEhiç değiştirilmesi mantıklı değildir .