Search code examples
windows-7cygwingroup-policy

Best strategy for installing cygwin under restrictive IT policies?


My organization has a group policy in effect that will only allow executable programs to reside under the Program Files (or Program Files X86) directory. Obviously, these directories are not writable by normal users. I have access to local admin rights, so I can install things there if I want. But of course it doesn't make sense to put the whole cygwin tree there, since users need to be able to write to /home, /tmp, etc. I am thinking I might be able to do something with links, maybe install to c:\cygwin, then move just the /bin directory under Program Files and create a hard link to it?

Has anyone run into a similar situation and come up with an elegant solution? This is Win 7 Enterprise.


Solution

  • Prior to Cygwin 1.7.34, solving such problems required a fair bit of hoop-jumping,¹ but now it's easy:

    1. If you haven't installed Cygwin yet, do so.²

      If you have Cygwin installed already and you started with a version of Cygwin prior to 1.7.34, move /etc/passwd and /etc/group out of the way,³ then upgrade to the current version.

    2. Start the Cygwin Terminal.

    3. Open Cygwin's /etc/nsswitch.conf in your favorite text editor.⁴ Add a line like this:

      db_home: /%H
      

    That's it! When you next re-start Cygwin, it will treat your Windows profile directory as your Cygwin home directory.⁵ This means you will have useful sub-folders like Desktop and Downloads as sub-folders, which matches the way OS X and a lot of desktop Linuxes work.

    Some people might not want these two directories to be treated as equivalents. You can choose any path scheme you like. For example, you could change it to /cygdrive/c/Users/%U/cygwin to put your Cygwin home folder into a cygwin subdirectory of your Windows profile directory.

    This new feature of Cygwin is very powerful and can do a lot more than I show here. For example, you can change a Cygwin user home directory via AD instead, if you like. See that documentation for details.

    You might also want to rearrange a few other elements of the Cygwin path scheme. You can do so by editing Cygwin's /etc/fstab file. You probably want to move /tmp, /usr/tmp, and /var/tmp to a directory that non-admin users can write to, for one thing:

    c:/tmp  /tmp      ntfs  auto  0 0
    c:/tmp  /usr/tmp  ntfs  auto  0 0
    c:/tmp  /var/tmp  ntfs  auto  0 0
    

    This will let you install (and later update) Cygwin as an Administrator while still letting unprivileged users run Cygwin. This makes Cygwin behave more like Linux or Unix. Since most software in the Cygwin package repository comes from that world, you can count on it to behave correctly under such a scheme.


    Footnotes:

    1. The first version of this answer tells you how to do an equivalent thing with older versions of Cygwin.

    2. Cygwin doesn't care where you install it, so if the default doesn't work for you, feel free to change it. Some ideas:

      • C:\Program Files\Cygwin
      • C:\Users\jeremy\Cygwin
      • D:\cygwin

      Cygwin will remember your choice on subsequent updates.

    3. If you don't move these files out of the way, they interfere with the solution we build above. This part of Cygwin is complex enough to deserve a whole section in the Cygwin user manual. Hint. :)

    4. Cygwin installs a stripped-down version of the Vim text editor by default.

      If you don't like vi, there are many other text editors in the Cygwin package repository.

      If you do like vi, I suggest installing the full version of Vim, then adding alias vi=vim to your ~/.bashrc.

      You can also use a native Windows GUI text editor. Cygwin's /etc/nsswitch.conf parser appears to cope with DOS line endings.

    5. The Cygwin DLL is building this path from the %HOMEDRIVE% and %HOMEPATH% environment variables, then converting it to POSIX form.