Question

j'essaie de mettre à jour le répertoire de base en toute sécurité, comme indiqué dans / etc / passwd , mais les utilitaires Linux standard - usermod et vipw - ne sont pas fournis. de Cygwin.

Quelqu'un pourrait-il me dire comment ils ont changé cela dans Cygwin?

Était-ce utile?

La solution 2

J'ai fini par sortir de tous mes shells cygwin et de le modifier à la main dans un éditeur de texte. Jusqu'ici, tout va bien.

Remarque: n'échappez pas aux espaces du champ "Documents et paramètres". annuaire. L'entrée ressemblera à

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

La ligne est marquée sur le caractère : .

Autres conseils

MODIFIER: Pour consulter les dernières versions de Cygwin (versions 1.7.34 et ultérieures), voir cette nouvelle question .

Comme la réponse de sblundy, vous pouvez toujours éditer à la main.

Mais si vous voulez le faire, le " officiel " Pour ce faire, utilisez le mkpasswd spécifique à cygwin. > commande. Vous trouverez ci-dessous un extrait de la documentation officielle sur mkpasswd . :

  

Par exemple, cette commande:

     

Exemple 3.11. Utilisation d'une autre racine racine

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

placerait les répertoires de base des utilisateurs locaux dans le répertoire "Profils" de Windows.

De nombreuses autres commandes très utiles sont décrites dans les Cygwin Utilities. page de documentation (qui comprend mkpasswd ). L'utilisation de cygpath dans l'exemple ci-dessus est un autre de ces outils spécifiques à cygwin.

Pendant que vous y êtes, vous voudrez probablement aussi lire le Utiliser Cygwin Effectivement avec la documentation Windows . Il y a beaucoup de très bons conseils.

La réponse la plus simple que j'ai trouvée est de faire de / home un lien symbolique vers votre répertoire Windows Home / UserProfile

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

J'ai utilisé cygpath car il obtiendra le bon emplacement pour le répertoire HOME sur la version actuelle de Windows. Sur ma boîte, cygpath -H renvoie / cygdrive / c / Users

.

Pour l'utilisateur actuel, les éléments suivants ont fonctionné pour moi:

  1. Fermez Cygwin.
  2. Définissez la variable d'environnement utilisateur Windows HOME.
  3. Démarrer Cygwin.
  4. exécutez "mkpasswd -c -p" $ (cygpath -H) " > / etc / passwd ".
  5. Redémarrez Cygwin.

J'ai confirmé que cela fonctionnait en exécutant ssh-keygen sans aucun argument. Après avoir effectué cette modification, l'application utilise désormais par défaut la clé dans / cygdrive / c / Users / user au lieu de / home / user.

Je ne sais pas si la configuration de HOME est requise, mais je l’ai quand même fait conformément aux instructions de configuration de TortoiseGit avec Cygwin, à l’aide de la documentation officielle de Tortoise concernant le support non officiel de Cygwin ici . Définir HOME seul n’a cependant pas suffi à ssh-keygen pour reconnaître le changement de répertoire personnel.

Notez également que la documentation officielle de Cygwin sur cette question se trouve ici .

Confirmé sous Windows 7 avec Cygwin v1.7.35 64 bits.

Je règle toujours HOME comme variable d'environnement spécifique à l'utilisateur dans les propriétés de l'ordinateur.

Pour éviter les problèmes liés à la présence d'espaces dans le chemin d'accès à votre répertoire de base, utilisez la forme abrégée du répertoire "Profils" de Windows - c.-à-d. / cygdrive / c / DOCUME ~ 1 / user .

Vous pouvez le faire en tapant la commande:

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

J'aime que mon installation de cygwin soit synchronisée avec une clé USB et un autre ordinateur. Je déteste donc coder en dur le répertoire personnel. J'utilise le fichier cygwin.bat suivant:

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

SETLOCAL et ENDLOCAL s'assurent que SHELL et HOME n'empilent pas les variables env existantes pour d'autres programmes. HOME =% ~ dp0 .. \ .. \ doc \ unix définit HOME de deux répertoires vers le haut, dans le sous-répertoire doc / unix. Puis, dans .... \ doc \ unix.bashrc, j'inclus PATH = "/ bin: / usr / local / bin: / usr / X11R6 / bin: / usr / bin" . Je n'ai pas utilisé démarrer / attendre% CD% \ bin \ bash pour démarrer bash, car j'utilise Console2 , je n'ai donc pas besoin d'une fenêtre cmd supplémentaire.

Utilisation de la variable d'environnement Windows: HOME

Cela fonctionne pour moi pour une solution permanente, non portable, sans réseau; c'est-à-dire définir la variable d'environnement HOME de manière permanente dans Windows.

Notez que cela n'affecte pas les sessions ssh ou telnet qui font toujours référence à / etc / passwd

ref: Configurer la variable d’environnement Cygwin- My HOME n’est pas ce que je veux.

CMD

Pour l'utilisateur actuel (doit être exécuté une fois par utilisateur) ::

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

Pour les nouveaux utilisateurs:

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

Remarque: Les caractères ^ avant pourcent-signes%

FICHIER REG D'IMPORTATION

Importer ce fichier reg (utilisateur actuel ):

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

Pour les nouveaux utilisateurs:

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

Dans Regedit, sous:

Pour utilisateur actuel :

HKEY_CURRENT_USER\Environment

Pour les nouveaux utilisateurs:

HKU\.DEFAULT\Environment

Créez HOME en tant que nouvelle valeur de chaîne extensible (* REG_EXPAND_SZ *) et insérez % 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top