Différences entre versions de « Cygwin »

De Cliss XXI
Sauter à la navigation Sauter à la recherche
imported>VincentAdolphe
m (A protégé « Cygwin » ([edit=sysop] (infini) [move=sysop] (infini)))
imported>VincentAdolphe
Ligne 66 : Ligne 66 :
 
  * relancer le serveur sshd (a faire en une seule ligne!):
 
  * relancer le serveur sshd (a faire en une seule ligne!):
 
   * cygrunsrv -E sshd ; cygrunsrv -S sshd
 
   * cygrunsrv -E sshd ; cygrunsrv -S sshd
 +
 +
== Installation initial simplifiée (chocolatey) ==
 +
L'idée ici est de configurer l'accès ssh le plus rapidement possible (on limite l'installation d'autre paquets) et d'utiliser "ssh-host-config" pour créer l'utilisateur "root" dont on aura besoin par la suite avec backuppc.
 +
Les difficultés c'est que sous windows il va falloir quand même faire quelques manip sur l'interface graphique (creer un raccourci et lancer 2 terminaux admin), que la suite d'instruction n'est absolument pas idempotente (notamment la partie ssh-host-config)
 +
 +
* installer chocolatey depuis le site http://chocolatey.org:
 +
** creer un raccourci sur le bureau vers "cmd". Faire un clic droit dessus et le lancer en tant qu'administrateur <pre>@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"</pre>
 +
** ou (windows 10 et au dessus) faire un clic droit sur le menu demarrer et lancer un powershell en tant qu'administrateur <pre>Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))</pre>
 +
 +
# installer cygwin et cyg-get
 +
choco install -y cygwin cyg-get
 +
 +
# ouvrir le firewall (ssh et ping):
 +
netsh advfirewall firewall add rule name="ssh" dir=in action=allow protocol=TCP localport=22
 +
netsh advfirewall firewall add rule name="ICMP ping" protocol=icmpv4:8,any dir=in action=allow
 +
# si ca ne marche pas (windows XP): netsh firewall add portopening TCP 22 "ssh" ; netsh firewall set icmpsetting 8
 +
 +
# lancer une console cygwin admin:
 +
C:\tools\cygwin\bin\mintty.exe -
 +
 +
* dans la console cygwin taper les commandes suivantes
 +
# installer openssh
 +
cyg-get.bat openssh
 +
 +
## transcription:
 +
# should strict mode be used ? -> yes
 +
# new local account "sshd" ? -> yes
 +
# install sshd as a service ? -> yes
 +
# enter value for CYGWIN [] -> '' (rien)
 +
# this script plan to use cyg_server / use a different name ? -> yes
 +
# enter the new username -> 'root'
 +
# enter it again -> 'root'
 +
# create new privileged user account ...root ? -> yes
 +
# enter password -> PASS
 +
# again -> PASS
 +
 +
# automation
 +
ROOT_PASS='aStrongPassword'
 +
ssh-host-config --debug --yes --name 'sshd' --port 22 --user 'root' --pwd "$ROOT_PASS"
 +
# lancer le service ssh
 +
cygrunsrv.exe --start sshd
 +
# cacher l'utilisateur root:
 +
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts'
 +
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList'
 +
regtool -d set '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList\root' 0
 +
 +
* tester l'acces ssh depuis l'exterieur: <pre>ssh <machine></pre> et terminer la configuration:
 +
# installer tightvnc
 +
choco install -y tightvnc
 +
# configurer tightvnc service:
 +
regtool  get '\HKLM\software\tightvnc\server\accepthttpconnections'
 +
regtool  set '\HKLM\software\tightvnc\server\accepthttpconnections' 0
 +
regtool  set '\HKLM\software\tightvnc\server\UseVncAuthentication' 1
 +
# set password (8 char, set the pass with vncpasswd on linux(pkg: tigervnc-common) PASS=$(echo 'pass' | vncpasswd -f | hexdump -v -e '/1 "%02x "')
 +
regtool --binary get '\HKLM\software\tightvnc\server\password'
 +
regtool --binary set '\HKLM\software\tightvnc\server\password' $PASS  # de la forme: aa c5 40 87 88 f1 fb 16
 +
# restart tight vnc server:
 +
net stop tvnserver
 +
net start tvnserver
 +
# note the gui controler quit but tightvncserver is running
  
 
== Maintenance ==
 
== Maintenance ==

Version du 30 octobre 2017 à 18:47

Cygwin est un environnement de type unix pour windows.


Preparation

Certain antivirus cassent des paquet avec des faux positif sur les bibliotheque de crypto comme cyghogweed.

Pour verifier les dependances d'un paquet:

cygcheck <paquet>

notes particuliere si l'intallation est faite a distance via VNC

  • changer les parametres de veille des machines pour eviter de perdre betement la main (creer un profil secteur/toujours allume si besoin)
  • creer un compte "root" avec les droits administrateurs et basculer dessus (ca limite les interference a cause de malware ou autres programmes se lancant au demarrage sans y etre invite).
  • si besoin commencer par faire du nettoyage (c'est une partie longue et difficile a faire en VNC)
  • telecharger et installer cygwin

- attention au fichier de clef ssh de machine qui arrivent de temps en temps en 660 (rw-rw----) sshd n'aime pas et ne demarre pas. changer en 600 (rw-------).

Note: en VNC il arrive que certains caracteres ne passent pas (par exemple l'arobase @ ce qui embetant pour configurer une messagerie). Dans ce cas la, on sort sa table ascii (decimale) et on peut taper le caractere avec ALT et le pave numerique. Pour l'arobase, dont le code ascii est 64 ca sera donc ALT + 6 4 (6 et 4 sur le pave numerique). Le type de client VNC influe beaucoup dans ce cas la.

Installation initiale

choisir quelques paquets incontournables:

* ssh / sshd
* rsync
* python / python-simplejson
* wget
* emacs

Installation SSH

faire un ssh-host-config

Installer gestionnaire de paquet

* wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
* chmod +x apt-cyg
* mv apt-cyg /usr/local/bin/
* exemple: apt-cyg install bc

Configuration

  • creer un utilisateur "root" avec les droits administrateur
    • depuis windows ...
    • depuis cygwin:
net user <username> <password> /add
net localgroup Administrators <username> /add
    • ajouter cet utilisateur dans le fichier passwd et group (il est sans doute necessaire de se connecter en tant que root pour que ce soit effectif):
mkpasswd -l > /etc/passwd
mkgroup -l > /etc/groups
  • cacher certains utilisateur (root, cyg_server) au login (avec reg)
reg add 'HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList' /v root /t REG_DWORD /d 0
reg add 'HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList' /v cyg_server /t REG_DWORD /d 0
reg query 'HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList'
  • cacher certains utilisateur (root, cyg_server) au login (avec regtools)
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts'
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList'
regtool -d set '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList\root' 0
regtool -d set '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList\cyg_server' 0
regtool -p list '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList'
regtool get '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList\root'


  • login par clef ssh
* installer les clef dans .ssh/authorized_keys de root
* tester le login avec les clefs
* editer /etc/sshd_config pour interdire le login par mot de passe
* relancer le serveur sshd (a faire en une seule ligne!):
 * cygrunsrv -E sshd ; cygrunsrv -S sshd

Installation initial simplifiée (chocolatey)

L'idée ici est de configurer l'accès ssh le plus rapidement possible (on limite l'installation d'autre paquets) et d'utiliser "ssh-host-config" pour créer l'utilisateur "root" dont on aura besoin par la suite avec backuppc. Les difficultés c'est que sous windows il va falloir quand même faire quelques manip sur l'interface graphique (creer un raccourci et lancer 2 terminaux admin), que la suite d'instruction n'est absolument pas idempotente (notamment la partie ssh-host-config)

  • installer chocolatey depuis le site http://chocolatey.org:
    • creer un raccourci sur le bureau vers "cmd". Faire un clic droit dessus et le lancer en tant qu'administrateur
      @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    • ou (windows 10 et au dessus) faire un clic droit sur le menu demarrer et lancer un powershell en tant qu'administrateur
      Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# installer cygwin et cyg-get
choco install -y cygwin cyg-get

# ouvrir le firewall (ssh et ping):
netsh advfirewall firewall add rule name="ssh" dir=in action=allow protocol=TCP localport=22
netsh advfirewall firewall add rule name="ICMP ping" protocol=icmpv4:8,any dir=in action=allow
# si ca ne marche pas (windows XP): netsh firewall add portopening TCP 22 "ssh" ; netsh firewall set icmpsetting 8

# lancer une console cygwin admin:
C:\tools\cygwin\bin\mintty.exe -
* dans la console cygwin taper les commandes suivantes
# installer openssh
cyg-get.bat openssh

## transcription:
# should strict mode be used ? -> yes
# new local account "sshd" ? -> yes
# install sshd as a service ? -> yes
# enter value for CYGWIN [] ->  (rien)
# this script plan to use cyg_server / use a different name ? -> yes
# enter the new username -> 'root'
# enter it again -> 'root'
# create new privileged user account ...root ? -> yes
# enter password -> PASS
# again -> PASS

# automation
ROOT_PASS='aStrongPassword'
ssh-host-config --debug --yes --name 'sshd' --port 22 --user 'root' --pwd "$ROOT_PASS"
# lancer le service ssh
cygrunsrv.exe --start sshd
# cacher l'utilisateur root:
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts'
regtool add '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList'
regtool -d set '\HKLM\software\microsoft\windows nt\currentversion\winlogon\SpecialAccounts\UserList\root' 0
  • tester l'acces ssh depuis l'exterieur:
    ssh <machine>
    et terminer la configuration:
# installer tightvnc
choco install -y tightvnc
# configurer tightvnc service:
regtool  get '\HKLM\software\tightvnc\server\accepthttpconnections'
regtool  set '\HKLM\software\tightvnc\server\accepthttpconnections' 0
regtool  set '\HKLM\software\tightvnc\server\UseVncAuthentication' 1
# set password (8 char, set the pass with vncpasswd on linux(pkg: tigervnc-common) PASS=$(echo 'pass' | vncpasswd -f | hexdump -v -e '/1 "%02x "')
regtool --binary get '\HKLM\software\tightvnc\server\password'
regtool --binary set '\HKLM\software\tightvnc\server\password' $PASS  # de la forme: aa c5 40 87 88 f1 fb 16
# restart tight vnc server:
net stop tvnserver
net start tvnserver
# note the gui controler quit but tightvncserver is running

Maintenance

Liste des services

* sc
* cygrunsrv

La base de registre

* regedit (export/import)
 * regedit /e <fichier> [<chemin>]
 * regedit /s <fichier>
* reg
 * reg query <chemin>
 * reg add <chemin_existant>/<nouveau_chemin> /v <valeur> /t <type_donnee> /d <donnee>

les partages windows

* net /?