Files
mkdocs/docs/Windows/wsl_2.md
2020-05-31 10:56:33 +02:00

5.6 KiB

Personnaliser WSL

PowerShell

Installer git:

PS choco install git.install --params "/GitAndUnixToolsOnPath /NoGitLfs /NoAutoCrlf"

Installer Posh-Git and Oh-My-Posh:

https://github.com/JanDeDobbeleer/oh-my-posh?WT.mc_id=-blog-scottha

PS Install-Module posh-git -Scope CurrentUser
PS Install-Module oh-my-posh -Scope CurrentUser

Si PowerShell a besoin de NuGet, il propose de l'installer:

PS Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

Configuration de PowerShell:

Exécuter "notepad $PROFILE" et ajouter à la fin:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

Installer les polices:

Depuis WSL (linux)


# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

Depuis PowerShell

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
.\install.ps1
#clean up
cd ..
rd /S /Q fonts

WSL

Installer zsh:

$ sudo apt-get install zsh curl git

$ chsh -s $(which zsh)

Installer antibody:

$ curl -sfL git.io/antibody | sudo sh -s - -b /usr/local/bin
[sudo] password for bruno:
getantibody/antibody info checking GitHub for latest tag
getantibody/antibody info found version: 6.0.1 for v6.0.1/Linux/x86_64
getantibody/antibody info installed /usr/local/bin/antibody

On restaure .zshrc .zsh_plugins.txt .dircolors

$ curl https://clicclac.info/backup/zsh_win10.tar.gz | tar -xzv

On met à jour les plugins antibody

$ antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh

Installer z plugin:

$ cd /usr/local/etc/profile.d/z/

#Créer les dossiers profile.d et z si ils n'existent pas.

#Cloner le répertoire
git clone https://github.com/rupa/z.git

Ajouter la ligne suivante au .zshrc

. /usr/local/etc/profile.d/z/z.sh

SSH

Générer une paire de clé ssh sous Windows:

PS ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\bruno/.ssh/id_rsa):
Created directory 'C:\Users\bruno/.ssh'.

Copier les clés dans wsl:

$ cp -r /mnt/c/Users/<username>/.ssh ~/.ssh

# Corriger les autorisations:
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*

Installer keychain dans wsl:

$ sudo apt install keychain

Copier la clé sur le serveur:

cat ~/.ssh/id_rsa.pub | ssh bruno@maboiteverte.fr 'cat>> ~/.ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh sentier@sur-le-sentier.fr 'cat>> ~/.ssh/authorized_keys'
cat ~/.ssh/id_rsa.pub | ssh -p42666 bruno@clicclac.synology.me 'cat>> ~/.ssh/authorized_keys'

Si il n'y a qu'une seule clé sur le serveur (scp écrase authorized_keys)

scp -P42666 C:\Users\bruno\.ssh\id_rsa.pub bruno@clicclac.synology.me:~/.ssh/authorized_keys

Ne plus demander la passphrase ssh:

https://medium.com/@glsorre/windows-subsystem-for-linux-never-prompt-your-ssh-passphrase-again-353db7c931ab

Installer CredentialManager:

PS Install-Module -Name CredentialManager

Copier les 2 fichiers suivants dans /home/[YOUR_WSL_USERNAME]/wslu/

keychain.ps1:

$credentials = Get-StoredCredential -Target sshpassphrase
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($credentials.Password)
$passphrase = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
C:\Windows\System32\wsl.exe -u [YOUR_WSL_USERNAME] -d [YOUR_DISTRIBUTION] /home/[YOUR_WSL_USERNAME]/wslu/keychain.sh $passphrase

keychain.sh:

#!/bin/bash
SSH_ASKPASS_SCRIPT=/tmp/ssh-askpass-script
cat > ${SSH_ASKPASS_SCRIPT} <<EOL
#!/bin/bash
echo "$1"
EOL
chmod u+x ${SSH_ASKPASS_SCRIPT}
export DISPLAY="0"
export SSH_ASKPASS=${SSH_ASKPASS_SCRIPT}
/usr/bin/keychain --clear id_rsa
rm ${SSH_ASKPASS_SCRIPT}

Ouvrir dans le Gestionnaire d'identification:

Panneaux de configuration -> Gestionnaire d'identification -> Information d'identification Windows -> Ajouter des informations d'identification génériques

  • Adresse Internet ou réseau: sshpassphrase (le mot passphrase)
  • Nom d'utilisateur: sshpassphrase (le mot passphrase)
  • Mot de passe: (la passphrase)

Ouvrir le Planificateur de taches:

Panneaux de configuration -> Outils d'administration -> Planificateur de taches -> Créer une tache de base

  • Général:

    • Mettre un nom: Launch Keychain

    • Configuré pour Windows 10

  • Déclencheur:

    • quand j'ouvre une session
  • Action: démarrer un programme

    • Programme/script: powershell
    • Ajouter des arguments: -File C:\Users\bruno\wslu\keychain.ps1

VS Code

Avoir VisualCode en français:

Rechercher 'French language' dans les extensions

VScode et wsl:

Afficher la palette de commande (Ctrl+Maj+P) et entrer Remote-WSL: New Window Depuis le terminal, taper code . ou code-insiders .

La commande code est dispo depuis le terminal. Si elle ne l'est pas, vérifier que VS Code est dans le PATH.

Sinon ajouter la ligne suivante au .zshrc

# VS Code
export PATH="/mnt/c/Program Files/Microsoft VS Code/bin:$PATH"

###Changer les couleurs pour ls:

LS_COLORS="ow=01;36;40" && export LS_COLORS

cd utilise les couleurs ls.

zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit

Fin

$ uname --release
 4.19.84-microsoft-standard

# 08-08-2020