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

297 lines
5.6 KiB
Markdown

# Personnaliser WSL
### PowerShell
#### Installer git:
```powershell
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
```powershell
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:
```powershell
PS Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
```
```powershell
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
```
#### Configuration de PowerShell:
Exécuter "notepad $PROFILE" et ajouter à la fin:
```powershell
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
```
#### Installer les polices:
Depuis WSL (linux)
```bash
# 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
```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:
```bash
$ sudo apt-get install zsh curl git
$ chsh -s $(which zsh)
```
#### Installer antibody:
```bash
$ 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
```bash
$ curl https://clicclac.info/backup/zsh_win10.tar.gz | tar -xzv
```
On met à jour les plugins antibody
```bash
$ antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh
```
#### Installer z plugin:
```bash
$ 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
```bash
. /usr/local/etc/profile.d/z/z.sh
```
### SSH
#### Générer une paire de clé ssh sous Windows:
```powershell
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:
```bash
$ cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
# Corriger les autorisations:
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*
```
#### Installer keychain dans wsl:
```bash
$ sudo apt install keychain
```
#### Copier la clé sur le serveur:
```bash
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)
```bash
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
<u>Installer CredentialManager:</u>
```powershell
PS Install-Module -Name CredentialManager
```
<u>Copier les 2 fichiers suivants dans</u> `/home/[YOUR_WSL_USERNAME]/wslu/`
*keychain.ps1:*
```powershell
$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:*
```bash
#!/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}
```
<u>Ouvrir dans le Gestionnaire d'identification:</u>
*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: <sshpassphrase> *(la passphrase)*
<u>Ouvrir le Planificateur de taches:</u>
*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 <u>Remote-WSL: New Window</u>
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`
```bash
# 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.
```bash
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
autoload -Uz compinit
compinit
```
### Fin
```bash
$ uname --release
4.19.84-microsoft-standard
# 08-08-2020
```