developer tip

설치 후 Cygwin 홈 폴더를 어떻게 변경합니까?

optionbox 2020. 7. 26. 12:53
반응형

설치 후 Cygwin 홈 폴더를 어떻게 변경합니까?


방금 Cygwin을 설치했는데 bash 프롬프트의 홈 디렉토리가 Z : 드라이브에있는 것처럼 보입니다. 내가 원하는 곳이 아닙니다.

이것을 어떻게 바꿀 수 있습니까?


Cygwin 1.7.34부터는 사용자 지정 db_home설정을 추가하는 것이 좋습니다 /etc/nsswitch.conf. Cygwin 홈 디렉토리를 Windows 사용자 프로파일 디렉토리와 동일하게 만드는 것이 일반적입니다. 이 설정은 다음을 수행합니다.

db_home: windows

또는 동등하게 :

db_home: /%H

Cygwin 홈 파일을 Windows 사용자 프로파일 디렉토리 서브 디렉토리 로 분리하는 것과 같이이 구성표를 약간 변형하려면 후자의 양식을 사용해야합니다 .

db_home: /%H/cygwin

windows옵션에 대한 몇 가지 다른 구성표 와 함께 또는 %대신에 사용할 수있는 몇 가지 다른 토큰이 있습니다 %H. 참조 구문 설명 에서 Cygwin에서 사용 설명서 자세한 내용입니다.nsswitch.conf

1.7.34 이전에 Cygwin을 설치했거나 파일 을 갖도록 mkpasswd유틸리티를 실행 한 경우 해당 /etc/passwd파일에서 사용자 항목을 편집하여 Cygwin 홈 디렉토리를 변경할 수 있습니다. 홈 디렉토리는 /etc/passwd의 사용자 라인에서 두 번째로 마지막 요소입니다.

어떤 방법을 사용하든 HOME쉘 시작 중에 환경 변수가 설정됩니다 .²

주제에 대한 자세한 내용은 이 FAQ 항목참조하십시오 .


각주 :

  1. 새로운 SAM / AD 기반 메커니즘을 대신 사용 하려면 이동 /etc/passwd이동을 고려하십시오 ./etc/group

  2. %HOME%제어판을 통해 간단하게 설정할 수 있지만 공식적으로 권장하지 않습니다 . 실수로 위의 메커니즘을 무시할뿐만 아니라를 통해 쉘 스크립트를 실행할 때와 같이 항상 작동하지는 않습니다 cron.


Cygwin 1.7.34+

Cygwin 1.7.34 이상을 사용하는 사용자는 Cygwin에서 홈 디렉토리, 로그인 쉘 및 gecos 정보를 가져 오는 방법 구성을 지원합니다 /etc/nsswitch.conf. Cygwin 사용 설명서 섹션에 자세히 설명되어 있습니다.

이전에 파일 /etc/passwd또는 /etc/group파일을 만든 경우 새 Windows 보안 모델과 POSIX 매핑을 사용하여 해당 파일을 제거하고 Cygwin을 구성해야합니다.

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

/etc/nsswitch.conf파일이있어 db_home:Cygwin에서 사용자의 홈 디렉토리를 가져 오는 방법을 정의하는 설정. 의 기본 설정 db_home:

db_home: /home/%U

따라서 기본적으로 Cygwin은 홈 디렉토리를로 설정합니다 /home/$USERNAME. 원하는 다른 사용자 정의 경로를 가리 키도록 변경할 수 있습니다. 지원되는 와일드 카드 문자는 다음과 같습니다.

  • %u Cygwin 사용자 이름 (소문자 u)
  • %U Windows 사용자 이름 (대문자 U)
  • %D NetBIOS 스타일의 Windows 도메인
  • %HPOSIX 스타일의 Windows 홈 디렉토리. 그 참고에 대한 db_home:설정, 이것은 단지에서와 같이 선행 슬래시 후 감지 권리를 만든다db_home: /%H/cygwin
  • %_공백과 TAB 문자는 스키마를 구분하는 데 사용되므로 파일 이름의 공백 %_은 밑줄로 지정해야합니다.
  • %% 퍼센트 문자.

경로 대신 미리 정의 된 4 개의 명명 된 경로 스키마 중 하나를 지정할 수 있습니다.

  1. windows사용자의 홈 디렉토리는 일반적으로 %USERPROFILE%또는 의 행을 따라 Windows 홈 디렉토리와 같은 디렉토리로 설정됩니다 C:\Users\$USERNAME. 물론 Windows 디렉토리는 Cygwin에 의해 POSIX 스타일로 변환됩니다.

  2. cygwinAD 전용 : 사용자의 홈 디렉토리가 cygwinUser 보조 클래스의 cygwinHome 속성에 지정된 POSIX 경로로 설정되어 있습니다. “cygwin 스키마”섹션 도 참조하십시오 .

  3. unixAD 전용 : 사용자의 홈 디렉토리가 posixAccount 보조 클래스의 unixHomeDirectory 속성에 지정된 POSIX 경로로 설정되어 있습니다. “Unix 스키마”섹션 도 참조하십시오 .

  4. desc사용자의 홈 디렉토리는 SAM 또는 AD의 사용자 설명 속성에서 home = "..."XML과 유사한 설정에 지정된 POSIX 경로로 설정됩니다. 자세한 설명은“데스크 스키마”를 참조하십시오.

다음은 Cygwin의 사용자 홈 디렉토리를 Windows 홈 디렉토리에 사용 된 것과 동일하게 만듭니다.

db_home: windows

Cygwin 1.7.33 이하

사용하는 사람들을 위해 Cygwin에서 1.7.33 거나 이전 업데이트 최신 버전의 Cygwin 제거 이전에 사용 /etc/passwd하고 /etc/group파일이 다음 위의 단계를 참조하십시오.

그렇지 않으면 아래의 이전 단계를 따르십시오.

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


I did something quite simple. I did not want to change the windows 7 environment variable. So I directly edited the Cygwin.bat file.

@echo off
SETLOCAL
set HOME=C:\path\to\home
C:
chdir C:\apps\cygwin\bin
bash --login -i
ENDLOCAL

This just starts the local shell with this home directory; that is what I wanted. I am not going to remotely access this, so this worked for me.


Cygwin mount now support bind method which lets you mount a directory. Hence you can simply add the following line to /etc/fstab, then restart your shell:

c:/Users /home none bind 0 0

Change your HOME environment variable.

on XP, its right-click My Computer >> Properties >> Advanced >> Environment Variables >> User Variables for >> [select variable HOME] >> edit


I'd like to add a correction/update to the bit about $HOME taking precedence. The home directory in /etc/passwd takes precedence over everything.

I'm a long time Cygwin user and I just did a clean install of Windows 7 x64 and Cygwin V1.126. I was going nuts trying to figure out why every time I ran ssh I kept getting:

e:\>ssh foo.bar.com
Could not create directory '/home/dhaynes/.ssh'.
The authenticity of host 'foo.bar.com (10.66.19.19)' can't be established.
...

I add the HOME=c:\users\dhaynes definition in the Windows environment but still it kept trying to create '/home/dhaynes'. I tried every combo I could including setting HOME to /cygdrive/c/users/dhaynes. Googled for the error message, could not find anything, couldn't find anything on the cygwin site. I use cygwin from cmd.exe, not bash.exe but the problem was present in both.

I finally realized that the home directory in /etc/passwd was taking precedence over the $HOME environment variable. I simple re-ran 'mkpasswd -l >/etc/passwd' and that updated the home directory, now all is well with ssh.

That may be obvious to linux types with sysadmin experience but for those of us who primarily use Windows it's a bit obscure.


I happen to use cwRsync (Cygwin + Rsync for Windows) where cygwin comes bundled, and I couldnt find /etc/passwd.

And it kept saying

Could not create directory '/home/username/.ssh'.
...
Failed to add the host to the list of known hosts (/home/username/.ssh/known_hosts).

So I wrote a batch file which changed HOME variable before running rsync. Something like:

set HOME=.
rsync /path1 user@host:/path2

And viola! .ssh folder appeared in current working dir and rsync stopped annoying with rsa fingerprints.

It's a quick hotfix, but later you should change HOME to a more secure location.

참고URL : https://stackoverflow.com/questions/1494658/how-can-i-change-my-cygwin-home-folder-after-installation

반응형