Programing

안전하게 홈 디렉토리 변경

lottogame 2020. 9. 24. 08:11
반응형

안전하게 홈 디렉토리 변경


에 지정된대로 홈 디렉토리를 안전하게 업데이트하려고하는데 /etc/passwd표준 Linux 유틸리티 인 usermod 및 vipw는 Cygwin에서 제공하지 않습니다.

누구든지 Cygwin에서 이것을 어떻게 변경했는지 말해 줄 수 있습니까?


편집 : Cygwin의 최신 버전 (1.7.34 이상)에 대해서는 이 최신 질문을 참조하십시오 .

sblundy의 답변처럼 언제든지 직접 편집 할 수 있습니다.

그러나 "공식적인"방식으로 수행하려면 cygwin 특정 mkpasswd명령을 사용하십시오 . 다음은에 대한 공식 문서의 스 니펫입니다 mkpasswd.

예를 들어 다음 명령은 다음과 같습니다.

예제 3.11. 대체 홈 루트 사용

$ mkpasswd -l -p "$(cygpath -H)" > /etc/passwd

로컬 사용자의 홈 디렉토리를 Windows 'Profiles'디렉토리에 넣습니다.

Cygwin 유틸리티 문서 페이지 (포함 mkpasswd) 에 설명 된 다른 정말 유용한 명령 이 많이 있습니다 . cygpath위의 예에서 의 사용은 이러한 cygwin 관련 도구 중 하나입니다.

그 동안 Windows 문서에서 Cygwin을 효과적으로 사용 하기를 원할 수도 있습니다. 정말 좋은 조언이 많이 있습니다.


결국 모든 cygwin 쉘을 종료하고 텍스트 편집기에서 직접 편집했습니다. 여태까지는 그런대로 잘됐다.

참고 : "Documents and Settings"디렉토리에서 공백을 이스케이프하지 마십시오. 항목은 다음과 같습니다.

user:...:/cygdrive/c/Documents and Settings/user:/bin/bash

라인은 :캐릭터에서 토큰 화됩니다 .


내가 찾은 가장 간단한 대답은 / home을 Windows Home / UserProfile 디렉터리에 대한 소프트 링크로 만드는 것입니다.

cd /
mv home oldhome
ln -s "$(cygpath -H)" home

현재 Windows 버전에서 HOME 디렉토리에 대한 적절한 위치를 얻을 수 있으므로 cygpath를 사용했습니다. 내 상자에 cygpath -H반환/cygdrive/c/Users


현재 사용자의 경우 다음이 저에게 효과적이었습니다.

  1. Cygwin을 닫습니다.
  2. HOME Windows 사용자 환경 변수를 설정합니다.
  3. Cygwin을 시작하십시오.
  4. "mkpasswd -c -p"$ (cygpath -H) "> / etc / passwd"를 실행하십시오.
  5. Cygwin을 다시 시작하십시오.

인수없이 ssh-keygen을 실행하여 작동하는지 확인했습니다. 이 변경 후 앱은 이제 기본적으로 키를 / home / user 대신 / cygdrive / c / Users / user에 저장합니다.

HOME 설정이 필요한지 모르겠지만 여기 비공식 Cygwin 지원을위한 Tortoise의 공식 문서를 사용하여 Cygwin으로 TortoiseGit을 설정하는 지침에 따라 수행했습니다 . ssh-keygen이 홈 디렉토리 변경을 인식하는 데는 HOME 만 설정하는 것만으로는 충분하지 않습니다.

또한이 문제에 대한 Cygwin의 공식 문서는 여기 에서 찾을 수 있습니다 .

64 비트 Cygwin v1.7.35를 사용하는 Windows 7에서 확인되었습니다.


항상 컴퓨터 속성에서 HOME을 사용자 별 환경 변수로 설정합니다.


홈 디렉토리 경로에 공백이있어 발생하는 문제를 방지하려면 Windows 'Profiles'디렉토리의 약식을 사용하십시오 /cygdrive/c/DOCUME~1/user. .

다음 명령을 입력하여이를 수행 할 수 있습니다.

mkpasswd -l -p "$(cygpath $(cygpath -dH))" > /etc/passwd

저는 cygwin 설치를 펜 드라이브와 다른 컴퓨터에 동기화하는 것을 좋아하므로 홈 디렉토리를 하드 코딩하는 것을 싫어합니다. 다음 cygwin.bat를 사용합니다.

echo off
SETLOCAL
set SHELL=\\bin\\bash
set HOME=%~dp0..\..\doc\unix
bin\bash --login -i
ENDLOCAL

SETLOCAL 및 ENDLOCAL은 SHELL 및 HOME이 다른 프로그램의 기존 환경 변수를 방해하지 않도록합니다. HOME=%~dp0..\..\doc\unixdoc / unix 하위 디렉토리에서 HOME을 두 개의 디렉토리 위로 설정합니다. 그런 다음 .... \ doc \ unix.bashrc에 PATH="/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin". Console2를start /wait %CD%\bin\bash 사용하고 있기 때문에 bash를 시작 하는 사용하지 않았 으므로 추가 cmd 창이 필요하지 않습니다.


Windows 환경 변수 사용 : HOME

이것은 영구적이고 휴대가 불가능하며 네트워크가 아닌 솔루션에 적합합니다. 즉, Windows에서 영구적으로 HOME 환경 변수를 설정합니다.

Note that this doesn't affect ssh or telnet sessions which always refer to /etc/passwd

ref: Setting up Cygwin- My HOME environment variable is not what I want.

CMD

For current user (needs to run once per user)::

reg add HKCU\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%

For new Users:

reg add HKU\.DEFAULT\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%

Note: Carets ^ before percent-signs %

IMPORT REG FILE

Import this reg file (current user):

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,00,00

For new users:

Windows Registry Editor Version 5.00

[HKU\.DEFAULT\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
  00,45,00,25,00,00,00

REGEDIT

In Regedit, under:

For current user:

HKEY_CURRENT_USER\Environment

For new Users:

HKU\.DEFAULT\Environment

Create HOME as a new Expandable String Value (*REG_EXPAND_SZ*) and put in %USERPROFILE%


Original answer by Christopher from elsewhere

Cygwin 1.7.34+

For those using Cygwin 1.7.34 or higher Cygwin supports configuring how to fetch home directory, login shell, and gecos information in /etc/nsswitch.conf. This is detailed in the Cygwin User Guide section:

If you've previously created an /etc/passwd or /etc/group file you'll want to remove those and configure Cygwin using the new Windows Security model to POSIX mappings.

[[ -f /etc/passwd ]] && mv /etc/passwd /etc/passwd.bak
[[ -f /etc/group ]] && mv /etc/group /etc/group.bak

The /etc/nsswitch.conf file's db_home: setting defines how Cygwin fetches the user's home directory. The default setting for db_home: is

db_home: /home/%U

So by default, Cygwin just sets the home dir to /home/$USERNAME. You can change that though to point at any other custom path you want. The supported wildcard characters are:

  • %u The Cygwin username (that's lowercase u).
  • %U The Windows username (that's uppercase U).
  • %D Windows domain in NetBIOS style.
  • %H Windows home directory in POSIX style. Note that, for the db_home: setting, this only makes sense right after the preceeding slash, as in db_home: /%H/cygwin
  • %_ Since space and TAB characters are used to separate the schemata, a space in the filename has to be given as %_ (that's an underscore).
  • %% A per-cent character.

In place of a path, you can specify one of four named path schemata that are predefined.

  1. windows The user's home directory is set to the same directory which is used as Windows home directory, typically something along the lines of %USERPROFILE% or C:\Users\$USERNAME. Of course, the Windows directory is converted to POSIX-style by Cygwin.

  2. cygwin AD only: The user's home directory is set to the POSIX path given in the cygwinHome attribute from the cygwinUser auxiliary class. See also the section called “The cygwin schema”.

  3. unix AD only: The user's home directory is set to the POSIX path given in the unixHomeDirectory attribute from the posixAccount auxiliary class. See also the section called “The unix schema”.

  4. desc The user's home directory is set to the POSIX path given in the home="..." XML-alike setting in the user's description attribute in SAM or AD. See the section called “The desc schema” for a detailed description.

The following will make the user's home directory in Cygwin the same as is used for the Windows home directory.

db_home: windows

Cygwin 1.7.33 or earlier

For those using Cygwin 1.7.33 or earlier, update to the latest version Cygwin and remove previously used /etc/passwd and /etc/group files, then see the steps above.

Else, follow these older steps below.

Firstly, set a Windows environment variable for HOME that points to your user profile:

  1. Open System on the Control Panel
  2. On the Advanced tab click Environment Variables (toward the bottom)
  3. In the User Variables area click "New…"
  4. For Variable name enter HOME
  5. For Variable value enter %USERPROFILE%
  6. Click OK in all the open dialog boxes to apply this new setting

Now we are going to update the Cygwin /etc/passwd file with the Windows %HOME% variable we just created. Shell logins and remote logins via ssh will rely on /etc/passwd to tell them the location of the user's $HOME path.

At the Cygwin bash command prompt type the following:

cp /etc/passwd /etc/passwd.bak
mkpasswd -l -p $(cygpath -H)  > /etc/passwd 
mkpasswd -d -p $(cygpath -H)  >> /etc/passwd 

The -d switch tells mkpasswd to include DOMAIN users, while -l is to only output LOCAL machine users. This is important if you're using a PC at work where the user information is obtained from a Windows Domain Controller.

Now, you can also do the same for groups, though this is not necessary unless you will be using a computer that is part of a Windows Domain. Cygwin reads group information from the Windows account databases, but you can add an /etc/group file if your machine is often disconnected from its Domain Controller.

At the Cygwin bash prompt type the following:

cp /etc/group /etc/group.bak
mkgroup -l > /etc/group 
mkgroup -d >> /etc/group 

Now, exit Cygwin and start it up again. You should find that your HOME path points to the same location as your Windows User Profile -- i.e. /cygdrive/c/Users/username


cd /home
rm -rf chris
ln -s /cygdrive/z chris

I am not really sure if it is the safest solution but it is a possible solution that works for me ;)


I edited my /etc/passwd file directly (making sure nothing else would be accessing it), and changed all references to /home to be /Users (on Windows 7). I found that, in order for everything to work correctly, I had to delete any directories in the /home directory (or move them to the appropriate other location). Otherwise, cygwin would develop a split personality where, for example, 'bash -l' would start in /home/Pablo but $HOME would be /Users/Pablo and emacs would appear to do the reverse. Once I deleted /home/Pablo, everything worked fine.


I only needed to be in C:\Users\username when I start cygwin. So, I just added to .bashrc and .profile

cd ${HOMEPATH}

If you prefer to use ~/. instead of $HOMEPATH, you can also add the following:

export HOME=${HOMEPATH}

This way I don't disturb the cygwin installation.

참고URL : https://stackoverflow.com/questions/225764/safely-change-home-directory

반응형