Aller au contenu

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-PoshPrompt -Theme cert

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

Installer zoxide

Ubuntu

wget http://archive.ubuntu.com/ubuntu/pool/universe/r/rust-zoxide/zoxide_0.4.3-2_amd64.deb

wget http://ports.ubuntu.com/pool/universe/r/rust-zoxide/zoxide_0.4.3-2_arm64.deb

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'.
d----          06/10/2021    17:23                .ssh

-a---          06/10/2021    17:23           2602 id_rsa
-a---          06/10/2021    17:23            571 id_rsa.pub

Copier les clés dans wsl:

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

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

Créer le ssh-agent:

$ eval $(ssh-agent -s)
Agent pid 3551

Ajouter la clé ssh au ssh-agent:

$ ssh-add
Enter passphrase for /home/bruno/.ssh/id_rsa: 
Identity added: /home/bruno/.ssh/id_rsa 

Installer keychain dans wsl:

$ sudo apt install keychain

et ajouter au .zshrc:

# on peut mettre toutes les clés que l'on veut attacher à la keychain
eval `keychain --eval --agents ssh ~/.ssh/id_rsa`

A la première ouverture du terminal, keychain demande la passphrase.

Pour les sessions suivantes, keychain indique que des clés sont chargées.

Liste des clés:

$ keychain --list
3072 SHA256:V/qyypJ2NVwfvQ8l8P/JBZcNC515j66MKG9HTAuDnX0 bruno@BRUNOPESENT79AA (RSA)

Décharger les clés en mémoire:

$ keychain --clear

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:

1.

# By default the ssh-agent service is disabled. Allow it to be manually started for the next step to work.
# Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Manual

# Start the service
Start-Service ssh-agent

# This should return a status of Running
Get-Service ssh-agent

# Now load your key files into ssh-agent
ssh-add ~\.ssh\id_rsa

2.

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

Pipe vers le presse-passier Windows:

Ajouter dans le .zshrc:

alias clip="clip.exe"

puis dans le shell:

grep alias .zshrc | clip

et coller (Ctrl+V) dans Notepad.

Fin

$ uname --release
 4.19.84-microsoft-standard

# 08-08-2020

Windows Toolbar Launcher:

https://github.com/cascadium/wsl-windows-toolbar-launcher

2021-08-31 13:13:54,707[INFO]: Finished creating 25 shortcuts!
2021-08-31 13:13:54,708[INFO]: Before raising an issue, make sure you have Xming / X410 etc set up in your .bashrc.
2021-08-31 13:13:54,708[INFO]: Right click on the toolbar, then select Toolbars -> New toolbar... and select the directory '/mnt/c/Users/bruno/.config/wsl-windows-toolbar-launcher/menus/WSL'.

https://opticos.github.io/openinwsl/

https://opticos.github.io/gwsl/

https://github.com/sirredbeard/Awesome-WSL

https://devblogs.microsoft.com/commandline/access-linux-filesystems-in-windows-and-wsl-2/


Dernière mise à jour: November 11, 2021