<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: klo2k</title>
    <description>The latest articles on DEV Community by klo2k (@klo2k).</description>
    <link>https://dev.to/klo2k</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F340328%2F9ff36e3f-d825-4b45-a91a-e1c1b1748b69.jpeg</url>
      <title>DEV Community: klo2k</title>
      <link>https://dev.to/klo2k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/klo2k"/>
    <language>en</language>
    <item>
      <title>Create Ubuntu 24.04.2 VM in Hyper-V, with "Enhanced Session" RDP support (Windows 11, xrdp, development)</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Fri, 07 Mar 2025 07:16:40 +0000</pubDate>
      <link>https://dev.to/klo2k/create-ubuntu-24042-vm-in-hyper-v-with-enhanced-session-rdp-support-windows-11-xrdp-1omk</link>
      <guid>https://dev.to/klo2k/create-ubuntu-24042-vm-in-hyper-v-with-enhanced-session-rdp-support-windows-11-xrdp-1omk</guid>
      <description>&lt;h1&gt;
  
  
  Create Ubuntu 24.04.2 VM in Hyper-V, with "Enhanced Session" RDP support (Windows 11, xrdp, development)
&lt;/h1&gt;

&lt;p&gt;To setup an Ubuntu 24.04.2 development Hyper-V VM, with built-in "Enhanced Session" + Remote Desktop Protocol (RDP) support (until it's available in Hyper-V's "Quck Create"):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Hyper-V VM&lt;/li&gt;
&lt;li&gt;Configure VM for "Enhanced Session", allow nested virtualisation&lt;/li&gt;
&lt;li&gt;Start VM, install Ubuntu&lt;/li&gt;
&lt;li&gt;XRDP Setup&lt;/li&gt;
&lt;li&gt;Optional, but really useful setup&lt;/li&gt;
&lt;li&gt;Fix Xrdp slow performance&lt;/li&gt;
&lt;li&gt;Connect to VM&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Create Hyper-V VM
&lt;/h2&gt;

&lt;p&gt;Create VM ("New" &amp;gt; "Virtual Machine"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Specify Name and Location
Name: Ubuntu 24.04
[Next]

# Specify Generation
Generation: 2
[Next]

# Assign Memory
Startup memory: 4096
[Next]

# Configure Networking
Connection: Default Switch
[Next]

# Connect Virtual Hard Disk
Create a virtual hard disk:
  Name: Ubuntu 24.04.vhdx
  Size: 256GB
[Next]

# Installation Options
Install an operating system from a from bootable CD/DVD-ROM:
  Image file: ubuntu-24.04.2-desktop-amd64.iso

[Finish]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DO NOT START VM YET&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Configure VM (Right-click "Ubuntu 24.04" &amp;gt; "Settings..."):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Change boot order (boot from HDD before Network)
Firmware
  DVD Drive
  HDD
  Network

# Necessary to boot Ubuntu
Security
  Enable Secure Boot
  Template: Microsoft UEFI Certificate Authority

# Optional
Integration Services
  (Check all)

# Optional
Checkpoints
  (Uncheck) Use automatic checkpoints

# Optional
Automatic Stop Action
  Shut down the guest operating system

[OK]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DO NOT START VM YET&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure VM for "Enhanced Session", allow nested virtualisation
&lt;/h2&gt;

&lt;p&gt;From &lt;strong&gt;admin&lt;/strong&gt; PowerShell (Right-click "Windows PowerShell" &amp;gt; "Run as administrator..."):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Connect with Enhanced Session&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Set-VM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-VMName&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'Ubuntu 24.04'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-EnhancedSessionTransportType&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;HvSocket&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# Allow nested virtualisation (optional)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Set-VMProcessor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-VMName&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'Ubuntu 24.04'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ExposeVirtualizationExtensions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# Verify - expect 'True'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Get-VMProcessor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-VMName&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'Ubuntu 24.04'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExposeVirtualizationExtensions&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Start VM, install Ubuntu
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start VM, install with default options, using the latest installer (Update installer if promoted).&lt;/p&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;❗ Make sure &lt;code&gt;Require my password to log in&lt;/code&gt; is checked (this is needed for &lt;code&gt;xrdp&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Example Default installation options:
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Interactive installation
  Default selection
  Erase disk and install Ubuntu
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Restart - Hard-reset VM if you get error: &lt;code&gt;SQUASHFS error: Failed to read block&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;h2&gt;
  
  
  XRDP Setup
&lt;/h2&gt;

&lt;p&gt;Install Xrdp + apply Ubuntu 24.04 specific fixes:&lt;/p&gt;

&lt;p&gt;💡 You may find it easier to do this over SSH: &lt;code&gt;apt install -y openssh-server&lt;/code&gt;, then &lt;code&gt;ssh&lt;/code&gt; to new VM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# As root&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;su -

&lt;span class="c"&gt;# Hyper-V integration services&lt;/span&gt;
apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; linux-tools-virtual-hwe-24.04 linux-cloud-tools-virtual-hwe-24.04
&lt;span class="c"&gt;# Fix-up journal log error&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; /usr/libexec/hypervkvpd/
&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /usr/sbin/hv_get_dhcp_info /usr/libexec/hypervkvpd/hv_get_dhcp_info
&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /usr/sbin/hv_get_dns_info /usr/libexec/hypervkvpd/hv_get_dns_info

&lt;span class="c"&gt;# Install xrdp&lt;/span&gt;
apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; xrdp
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/xrdp/sesman.ini /etc/xrdp/sesman.ini.original
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.original

&lt;span class="c"&gt;# Allow enhanced session&lt;/span&gt;
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/^port=3389$/port=3389 vsock:\/\/-1:3389/g'&lt;/span&gt; /etc/xrdp/xrdp.ini

&lt;span class="c"&gt;# Rename redirected drives to 'shared-drives'&lt;/span&gt;
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g'&lt;/span&gt; /etc/xrdp/sesman.ini


&lt;span class="c"&gt;# Use "Ubuntu" session&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/xrdp/startubuntu.sh &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
#!/bin/sh
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
exec /etc/xrdp/startwm.sh
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+x /etc/xrdp/startubuntu.sh
&lt;span class="c"&gt;# use the script to setup the ubuntu session&lt;/span&gt;
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/startwm/startubuntu/g'&lt;/span&gt; /etc/xrdp/sesman.ini

&lt;span class="c"&gt;# Fixes login black screen delay&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"blacklist vmw_vsock_vmci_transport"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf

&lt;span class="c"&gt;# Unlock keyring on login&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/pam.d/xrdp-sesman &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
#%PAM-1.0
auth     required  pam_env.so readenv=1
auth     required  pam_env.so readenv=1 envfile=/etc/default/locale
@include common-auth
-auth    optional  pam_gnome_keyring.so
-auth    optional  pam_kwallet5.so

@include common-account

@include common-password

# Ensure resource limits are applied
session    required     pam_limits.so
# Set the loginuid process attribute.
session    required     pam_loginuid.so
# Update wtmp/lastlog
session    optional     pam_lastlog.so quiet
@include common-session
-session optional  pam_gnome_keyring.so auto_start
-session optional  pam_kwallet5.so auto_start
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optional, but really useful setup
&lt;/h2&gt;

&lt;p&gt;Reduce boot delay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/default/grub /etc/default/grub.default
&lt;span class="c"&gt;# Show boot log instead of splash screen&lt;/span&gt;
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=""/g'&lt;/span&gt; /etc/default/grub
&lt;span class="c"&gt;# Faster boot - reduce grub wait for input timeout&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'GRUB_RECORDFAIL_TIMEOUT=3'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/default/grub
update-grub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable zram (compressed memory), disable swap file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; systemd-zram-generator
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/systemd/zram-generator.conf /etc/systemd/zram-generator.conf.original
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/systemd/zram-generator.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
[zram0]
zram-size = 12288
compression-algorithm = zstd
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;systemctl daemon-reload
systemctl restart systemd-zram-setup@zram0

&lt;span class="c"&gt;# Disable swap file&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/fstab /etc/fstab.original
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s@^/swap.img@#/swap.img@g'&lt;/span&gt; /etc/fstab
swapoff /swap.img
&lt;span class="nb"&gt;rm&lt;/span&gt; /swap.img
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full reboot (must power off &amp;gt; power on - else Enhanced Session won't kick-in)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poweroff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix Xrdp slow performance
&lt;/h2&gt;

&lt;p&gt;In Feb 2025 one of the Ubuntu update caused a performance regression with the Xorg backend (even on 1920x1080...).&lt;/p&gt;

&lt;p&gt;To switch to the VNC Backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# As root&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;su -

&lt;span class="c"&gt;# Install TigerVNC&lt;/span&gt;
apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; tigervnc-standalone-server tigervnc-xorg-extension

&lt;span class="c"&gt;# Configure tigervnc backend&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /etc/xrdp/sesman.ini /etc/xrdp/sesman.ini.20250213
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'s/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'\(\[Xvnc\].*\nparam=96\n\)\n\[/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'\1param=-CompareFB\nparam=1\nparam=-ZlibLevel\nparam=0\nparam=-geometry\nparam=1920x1080\n\n[/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'gi'&lt;/span&gt; /etc/xrdp/sesman.ini

&lt;span class="c"&gt;# Remove Xorg backend&lt;/span&gt;
&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'s/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'\[Xorg\].*\ncode=20\n\n\[/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'[/'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s1"&gt;'gi'&lt;/span&gt; /etc/xrdp/xrdp.ini

reboot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Connect to VM
&lt;/h2&gt;

&lt;p&gt;Either using &lt;code&gt;mstsc&lt;/code&gt; / Hyper-V&lt;/p&gt;

&lt;p&gt;Profit 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/milnak/54e662f88fa47a5d3a317edb712f957e" rel="noopener noreferrer"&gt;milnak's github gist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Hinara/linux-vm-tools/" rel="noopener noreferrer"&gt;Microsoft / Hinara's &lt;code&gt;linux-vm-tools&lt;/code&gt; repo&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ubuntu</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building Docker image from stdin/pipe</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Tue, 28 Feb 2023 06:51:03 +0000</pubDate>
      <link>https://dev.to/klo2k/building-docker-image-from-stdinpipe-1d73</link>
      <guid>https://dev.to/klo2k/building-docker-image-from-stdinpipe-1d73</guid>
      <description>&lt;p&gt;Using &lt;code&gt;-&lt;/code&gt; as &lt;code&gt;docker build&lt;/code&gt; parameter, you can pipe in any text as your Dockerfile.&lt;/p&gt;

&lt;p&gt;I use this trick to quickly test parts of a Dockerfile.&lt;/p&gt;

&lt;p&gt;e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Build the image, with '-' + heredoc as input&lt;/span&gt;
&lt;span class="c"&gt;# Works the same with pipe input&lt;/span&gt;
docker build &lt;span class="nt"&gt;--tag&lt;/span&gt; klo2k/test - &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
FROM ubuntu:latest

# Some complicated looking stuff you wanna try out quickly
RUN &amp;lt;&amp;lt;'EOS' /bin/bash
  echo "&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOSTNAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;" &amp;gt; /tmp/out
EOS

CMD echo "Build: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /tmp/out&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="sh"&gt; Run: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOSTNAME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;&lt;span class="c"&gt;# Run&lt;/span&gt;
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; klo2k/test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Build: buildkitsandbox Run: a16cd7dc16ed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope you find this useful!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>career</category>
      <category>githubcopilot</category>
    </item>
    <item>
      <title>Convert directory into BTRFS subvolume</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Mon, 27 Feb 2023 07:40:05 +0000</pubDate>
      <link>https://dev.to/klo2k/convert-directory-into-btrfs-subvolume-p98</link>
      <guid>https://dev.to/klo2k/convert-directory-into-btrfs-subvolume-p98</guid>
      <description>&lt;p&gt;I've been using BTRFS for development and am loving the simplicity and features it provides.&lt;/p&gt;

&lt;p&gt;One thing I do a lot is database snapshot on docker volume (to test db migration) - which I can easily do with BTRFS.&lt;/p&gt;

&lt;p&gt;Here's how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert docker volume directory into BTRFS subvolume&lt;/li&gt;
&lt;li&gt;Snapshot the docker volume (now a BTRFS subvolume)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Convert docker volume directory into BTRFS subvolume
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Directory to convert into BTRFS subvolume&lt;/span&gt;
&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'/var/lib/docker/test_docker_volume'&lt;/span&gt;

&lt;span class="c"&gt;# Rename original dierctory&lt;/span&gt;
&lt;span class="nb"&gt;mv&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_original"&lt;/span&gt;

&lt;span class="c"&gt;# Create btrfs subvolume&lt;/span&gt;
btrfs subvolume create &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Copy as "reflink" for speed and save space&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;--archive&lt;/span&gt; &lt;span class="nt"&gt;--one-file-system&lt;/span&gt; &lt;span class="nt"&gt;--reflink&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;always &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_original/."&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Remove old directory&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="nt"&gt;--one-file-system&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;dirPath&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_original"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Snapshot the docker volume
&lt;/h2&gt;

&lt;p&gt;Create a read-only snapshot of &lt;code&gt;test_docker_volume&lt;/code&gt; docker volume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;btrfs subvolume snapshot &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  /var/lib/docker/test_docker_volume &lt;span class="se"&gt;\&lt;/span&gt;
  /var/lib/docker/test_docker_volume_bak
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>redis</category>
      <category>llm</category>
      <category>ai</category>
    </item>
    <item>
      <title>Run Docker in WSL2 in 5 minutes (via systemd, without Docker Desktop!)</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Wed, 23 Nov 2022 07:08:35 +0000</pubDate>
      <link>https://dev.to/klo2k/run-docker-in-wsl2-in-5-minutes-via-systemd-without-docker-desktop-28gi</link>
      <guid>https://dev.to/klo2k/run-docker-in-wsl2-in-5-minutes-via-systemd-without-docker-desktop-28gi</guid>
      <description>&lt;p&gt;Now WSL2 has &lt;a href="https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/" rel="noopener noreferrer"&gt;systemd support&lt;/a&gt;, we can run Docker in WSL without Docker desktop!&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Ensure &lt;code&gt;/etc/wsl.conf&lt;/code&gt; has&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[boot]&lt;/span&gt;
&lt;span class="py"&gt;systemd&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Restart WSL&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--shutdown&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--distribution&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install docker-cli - see &lt;a href="https://dev.to/klo2k/install-docker-docker-compose-in-ubuntu-2204-in-5-commands-35m8"&gt;my guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Log back into WSL &amp;gt; Profit 💫&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Complete Guide
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Ensure WSL is up-to-date:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--update&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;(Optional) Install + configure Ubuntu distro (if you haven't already):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Configure WSL (assuming "Ubuntu" is your distro):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Open up "Ubuntu"&lt;/span&gt;
wsl &lt;span class="nt"&gt;--distribution&lt;/span&gt; Ubuntu

&lt;span class="c"&gt;# Enable systemd via /etc/wsl.conf&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;
[boot]
systemd=true
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/wsl.conf

&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Restart WSL:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--shutdown&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--distribution&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check systemd is running - You should see 'OK: Systemd is running' message:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl &lt;span class="nt"&gt;--no-pager&lt;/span&gt; status user.slice &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null 2&amp;gt;&amp;amp;1 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'OK: Systemd is running'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'FAIL: Systemd not running'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install docker-ce (cmds from &lt;a href="https://dev.to/klo2k/install-docker-docker-compose-in-ubuntu-2204-in-5-commands-35m8"&gt;my post&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install Docker&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://download.docker.com/linux/ubuntu/gpg | &lt;span class="nb"&gt;sudo &lt;/span&gt;gpg &lt;span class="nt"&gt;--dearmor&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /etc/apt/keyrings/docker.gpg
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"deb [arch=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;dpkg &lt;span class="nt"&gt;--print-architecture&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
  &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;lsb_release &lt;span class="nt"&gt;-cs&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; stable"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/docker.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; docker-ce docker-compose-plugin

&lt;span class="c"&gt;# Install docker-compose&lt;/span&gt;
&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose

&lt;span class="c"&gt;# Add yourself to the docker group&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; docker &lt;span class="nv"&gt;$USER&lt;/span&gt;

&lt;span class="c"&gt;# Exit bash - this is important!!!&lt;/span&gt;
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Re-login (this is important!):&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;wsl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--distribution&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Ubuntu&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can now run docker-cli without Docker Desktop 🙂:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; hello-world
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>opensource</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Connect DBeaver to Snowflake via Okta SSO (flatpak / snap)</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Mon, 31 Oct 2022 04:36:15 +0000</pubDate>
      <link>https://dev.to/klo2k/connect-dbeaver-to-snowflake-via-okta-sso-flatpak-snap-cn4</link>
      <guid>https://dev.to/klo2k/connect-dbeaver-to-snowflake-via-okta-sso-flatpak-snap-cn4</guid>
      <description>&lt;p&gt;DBeaver flatpak/snap doesn't allow you to log into Snowflake via browser-based SSO ("externalbrowser"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The BROWSE action is not supported on the current platform!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you happen to use Okta, you can use the &lt;a href="https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use.html#native-sso-okta-only" rel="noopener noreferrer"&gt;"Native SSO" feature&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Simply add &lt;code&gt;authenticator&lt;/code&gt; driver property, with your Okta instance's URL:&lt;br&gt;
i.e.:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2njwm92rbup7wtkz4fg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy2njwm92rbup7wtkz4fg.png" alt="dbeaver driver properties"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Username (&lt;code&gt;Main&lt;/code&gt; tab) would be your Snowflake username (i.e. &lt;code&gt;select current_user();)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note browser-based SSO works with the &lt;code&gt;.deb&lt;/code&gt; installer - but this method has the benefit of not spamming your browser with new tab every time dbeaver needs to re-authenticate.&lt;/p&gt;

</description>
      <category>dbeaver</category>
      <category>snowflake</category>
      <category>sso</category>
      <category>okta</category>
    </item>
    <item>
      <title>Fix SSD TRIM on UGREEN UASP USB SATA adapter/enclosure</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Thu, 22 Sep 2022 17:25:58 +0000</pubDate>
      <link>https://dev.to/klo2k/fix-ssd-trim-on-ugreen-uasp-usb-sata-adapterenclosure-5ge6</link>
      <guid>https://dev.to/klo2k/fix-ssd-trim-on-ugreen-uasp-usb-sata-adapterenclosure-5ge6</guid>
      <description>&lt;p&gt;I've finally figured out how to fix SSD TRIM on the newer UGREEN USB SATA &lt;a href="https://www.amazon.com.au/UGREEN-Adapter-Cable-Converter-Drives/dp/B07SCY623F/"&gt;adapter&lt;/a&gt; and &lt;a href="https://www.amazon.com.au/gp/product/B06XWRRMYX/"&gt;enclosure&lt;/a&gt;, both on my machine and Raspberry Pi-s!&lt;/p&gt;

&lt;p&gt;We need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set 'unmap' on &lt;code&gt;/sys/block/sda/device/scsi_disk/0:0:0:0/provisioning_mode&lt;/code&gt; (the standard fix)&lt;/li&gt;
&lt;li&gt;Set '2147450880' on &lt;code&gt;/sys/block/sda/queue/discard_max_bytes&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without the 2nd fix, &lt;code&gt;fstrim&lt;/code&gt; would only work on small partitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Permanent fix via UDEV Rules
&lt;/h2&gt;

&lt;p&gt;Add these udev rules to &lt;code&gt;/etc/udev/rules.d/99-ugreen-sata-adapter-trim-enable.rules&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# UGREEN SATA USB adapter cable - ASMedia Technology Inc. Ugreen Storage Device
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="225c", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="225c", SUBSYSTEM=="block", ATTR{queue/discard_max_bytes}="2147450880"

# UGREEN SATA Enclosure - ASMedia Technology Inc. ASM1153 SATA 3Gb/s bridge
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="1153", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="1153", SUBSYSTEM=="block", ATTR{queue/discard_max_bytes}="2147450880"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡: You may need to change &lt;code&gt;idProduct&lt;/code&gt; to your own - check &lt;code&gt;lsusb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;e.g. Here're mine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# `lsusb` output:&lt;/span&gt;
...
Bus 002 Device 034: ID 174c:225c ASMedia Technology Inc. Ugreen Storage Device
...
Bus 002 Device 041: ID 174c:1153 ASMedia Technology Inc. ASM1153 SATA 3Gb/s bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where did 2147450880 come from?
&lt;/h2&gt;

&lt;p&gt;It seems &lt;code&gt;fstrim&lt;/code&gt; can still fail on large partitions, with the default &lt;code&gt;discard_max_bytes&lt;/code&gt; value too big (4294966784) - we need to set it to the maximum the adapter can handle.&lt;/p&gt;

&lt;p&gt;2147450880 is this maximum in my case, calculated from 2 attributes from the adapter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Maximum unmap LBA count&lt;/code&gt; (from &lt;code&gt;sg_vpd&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Logical block length&lt;/code&gt; (from &lt;code&gt;sg_readcap&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a small snippet to show yours:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;su -
apt &lt;span class="nb"&gt;install &lt;/span&gt;sg3-utils

&lt;span class="c"&gt;# Device to check&lt;/span&gt;
&lt;span class="nv"&gt;device&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sdh
&lt;span class="c"&gt;# e.g. lba_count=4194240&lt;/span&gt;
&lt;span class="nv"&gt;lba_count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;sg_vpd &lt;span class="nt"&gt;--all&lt;/span&gt; /dev/&lt;span class="nv"&gt;$device&lt;/span&gt;|grep &lt;span class="s1"&gt;'Maximum unmap LBA count'&lt;/span&gt;|grep &lt;span class="nt"&gt;-Po&lt;/span&gt; &lt;span class="s1"&gt;'(?&amp;lt;=: )(.*)(?=$)'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;# e.g. block_length=512&lt;/span&gt;
&lt;span class="nv"&gt;block_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;sg_readcap &lt;span class="nt"&gt;--long&lt;/span&gt; /dev/&lt;span class="nv"&gt;$device&lt;/span&gt;|grep &lt;span class="s1"&gt;'Logical block length'&lt;/span&gt;|grep &lt;span class="nt"&gt;-Po&lt;/span&gt; &lt;span class="s1"&gt;'(?&amp;lt;=\=)(.*)(?= bytes)'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;# e.g. 2147450880&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="nv"&gt;$lba_count&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;$block_length&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Symptoms addressed by fix
&lt;/h2&gt;

&lt;p&gt;This fix will be relevant to you if you encounter these errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# fstrim -v /&lt;/span&gt;
fstrim: /: the discard operation is not supported
fstrim: /: FITRIM ioctl failed: Operation not permitted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in &lt;code&gt;/var/log/syslog&lt;/code&gt; / &lt;code&gt;journalctl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#12 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#12 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#12 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#12 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: print_req_error: 6703 callbacks suppressed
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 39667712 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#13 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#13 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#13 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#13 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 48056312 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#14 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#14 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#14 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#14 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 56444912 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 89999312 op 0x3:(DISCARD) flags 0x0 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#15 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#15 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#15 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#15 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 64833512 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#16 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#16 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#16 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#16 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 73222112 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#17 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#17 Sense Key : Illegal Request [current] 
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#17 Add. Sense: Invalid field in cdb
Sep 22 20:16:19 LINUX kernel: sd 7:0:0:0: [sdg] tag#17 CDB: Unmap/Read sub-channel 42 00 00 00 00 00 00 00 18 00
Sep 22 20:16:19 LINUX kernel: blk_update_request: critical target error, dev sdg, sector 81610712 op 0x3:(DISCARD) flags 0x4000 phys_seg 1 prio class 0
Sep 22 20:16:19 LINUX kernel: BTRFS warning (device sdg3): failed to trim 1 device(s), last error -95
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;This is only possible thanks to &lt;a href="https://www.jeffgeerling.com/blog/2020/enabling-trim-on-external-ssd-on-raspberry-pi"&gt;this post&lt;/a&gt; from Jeff Geerling (he's awesome 👍)&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>linux</category>
    </item>
    <item>
      <title>Keychron K5 Function Keys + Unstable Bluetooth fix - Ubuntu 22.04</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Fri, 08 Jul 2022 14:14:03 +0000</pubDate>
      <link>https://dev.to/klo2k/keychron-k5-function-keys-unstable-bluetooth-fix-ubuntu-2204-4em8</link>
      <guid>https://dev.to/klo2k/keychron-k5-function-keys-unstable-bluetooth-fix-ubuntu-2204-4em8</guid>
      <description>&lt;p&gt;If you have problem getting the F1 - F12 (Function) keys to work, and unstable bluetooth connection on your new Keychron K5 keyboard, this will hopefully help you.&lt;/p&gt;

&lt;p&gt;Here are the fixes that worked for me on Ubuntu 22.04.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing top row keys as F1 to F12
&lt;/h2&gt;

&lt;p&gt;So you can actually use the function key row as function keys:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set keyboard to Windows mode (use hardware switch)&lt;/li&gt;
&lt;li&gt;Hold Fn + X + L for 4 seconds to switch to "Function" mode&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apply the fix temporarily --&amp;gt; check if it's working:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;0 | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /sys/module/hid_apple/parameters/fnmode
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apply the fix permanently:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"options hid_apple fnmode=0"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /etc/modprobe.d/hid_apple.conf
&lt;span class="nb"&gt;sudo &lt;/span&gt;update-initramfs &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reboot (to verify)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Fixing unstable Bluetooth Connection
&lt;/h2&gt;

&lt;p&gt;Before this fix the keyboard would randomly disconnect.&lt;/p&gt;

&lt;p&gt;After this fix, not a single glitch the entire workday 😋&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Enable fast connect:&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/bluetooth/main.conf&lt;/code&gt; - uncomment and set these values:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;FastConnectable &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="nv"&gt;ReconnectAttempts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;7
&lt;span class="nv"&gt;ReconnectIntervals&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1, 2, 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Disable bluetooth auto suspend&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"options btusb enable_autosuspend=n"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/modprobe.d/btusb_disable_autosuspend.conf
&lt;span class="nb"&gt;sudo &lt;/span&gt;update-initramfs &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Restart bluetooth&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;modprobe &lt;span class="nt"&gt;-r&lt;/span&gt; btusb
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart bluetooth
&lt;span class="nb"&gt;sudo &lt;/span&gt;modprobe btusb
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Factory reset keyboard (Hold Fn + Z + J for 4 seconds) --&amp;gt; Re-pair keyboard&lt;/p&gt;

&lt;p&gt;This makes no sense but it did seem to make a difference...&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;p&gt;This post is possible thanks to these awesome people:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mikeshade.com/posts/keychron-linux-function-keys/"&gt;Mike Shade&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/andrebrait/961cefe730f4a2c41f57911e6195e444"&gt;andrebrait&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>keychron</category>
      <category>keyboard</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Install docker, docker-compose in Ubuntu 24.04 in 5 commands</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Fri, 01 Jul 2022 13:24:15 +0000</pubDate>
      <link>https://dev.to/klo2k/install-docker-docker-compose-in-ubuntu-2204-in-5-commands-35m8</link>
      <guid>https://dev.to/klo2k/install-docker-docker-compose-in-ubuntu-2204-in-5-commands-35m8</guid>
      <description>&lt;h1&gt;
  
  
  Install docker, docker-compose in Ubuntu 24.04 in 5 commands
&lt;/h1&gt;

&lt;p&gt;The &lt;a href="https://docs.docker.com/engine/install/ubuntu/" rel="noopener noreferrer"&gt;official guide&lt;/a&gt; takes a bit of reading...&lt;/p&gt;

&lt;p&gt;So here's the TL;DR version of it, in 5 commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install Docker&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://download.docker.com/linux/ubuntu/gpg &lt;span class="nt"&gt;-o&lt;/span&gt; /etc/apt/keyrings/docker.asc
&lt;span class="nb"&gt;chmod &lt;/span&gt;0644 /etc/apt/keyrings/docker.asc
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"deb [arch=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;dpkg &lt;span class="nt"&gt;--print-architecture&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; /etc/os-release &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$VERSION_CODENAME&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; stable"&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/docker.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; docker-ce docker-compose-plugin

&lt;span class="c"&gt;# Add yourself to 'docker' group&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;--append&lt;/span&gt; &lt;span class="nt"&gt;--groups&lt;/span&gt; docker &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Install docker-compose&lt;/span&gt;
&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add yourself to &lt;code&gt;docker&lt;/code&gt; group (no need for &lt;code&gt;sudo docker&lt;/code&gt; every time)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-aG&lt;/span&gt; docker &lt;span class="nv"&gt;$USER&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Profit 😉&lt;/p&gt;

</description>
      <category>docker</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Get Git to remember passwords - git credential manager examples</title>
      <dc:creator>klo2k</dc:creator>
      <pubDate>Tue, 28 Jun 2022 06:50:02 +0000</pubDate>
      <link>https://dev.to/klo2k/using-git-password-via-https-non-interactively-cicd-script-f5b</link>
      <guid>https://dev.to/klo2k/using-git-password-via-https-non-interactively-cicd-script-f5b</guid>
      <description>&lt;p&gt;Sometimes it's necessary to use password-based authentication via &lt;code&gt;https&lt;/code&gt; when using remote repo.&lt;/p&gt;

&lt;p&gt;When used in CI/CD pipelines, we need to do this non-interactively, and not expose password in the remote's URL.&lt;/p&gt;

&lt;p&gt;To do this, we can use git's own &lt;a href="https://git-scm.com/docs/git-credential"&gt;credential manager&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are some examples to help us understand and use it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
TL;DR (Full Example)

&lt;ul&gt;
&lt;li&gt;Setup&lt;/li&gt;
&lt;li&gt;Add password, pull from repo&lt;/li&gt;
&lt;li&gt;Clean-up&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
More Examples

&lt;ul&gt;
&lt;li&gt;Save credentials&lt;/li&gt;
&lt;li&gt;Get credentials&lt;/li&gt;
&lt;li&gt;Selectively remove credentials&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  TL;DR (Full Example)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Get a shell into git container&lt;/span&gt;
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="nt"&gt;--entrypoint&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/bin/sh alpine/git:v2.34.2

&lt;span class="c"&gt;# Store credentials to file&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; credential.helper store
&lt;span class="c"&gt;# Note: To store in memory (for 1 day)&lt;/span&gt;
&lt;span class="c"&gt;# git config --global credential.helper 'cache --timeout=86400'&lt;/span&gt;

&lt;span class="c"&gt;# Clean out existing credentials&lt;/span&gt;
&lt;span class="nb"&gt;rm&lt;/span&gt; ~/.git-credentials

&lt;span class="c"&gt;# Force non-interactive mode&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;GIT_TERMINAL_PROMPT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add password, clone from repo
&lt;/h3&gt;

&lt;p&gt;Add password&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git credential approve &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/jsmith/testrepo.git
username=jsmith
password=abc123
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clone repo - no password asked / exposed 😉️&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://jsmith@example.com/jsmith/testrepo.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Clean-up
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; ~/.git-credentials
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  More Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Save credentials
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git credential approve &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com
username=user0
password=0000
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;git credential approve &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/test-group/test-repo1.git
username=user1
password=1111
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;git credential approve &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/test-group/test-repo2.git
username=user2
password=2222
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get credentials
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git credential fill &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/test-group/test-repo1.git
username=user1
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;git credential fill &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/test-group/test-repo2.git
username=user2
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;git credential fill &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com
username=user0
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selectively remove credentials
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git credential reject &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com
username=user2
&lt;/span&gt;&lt;span class="no"&gt;EOT

&lt;/span&gt;&lt;span class="c"&gt;# Ensure it's removed - expect to error-out with "fatal: could not read Password for 'https://user2@example.com': terminal prompts disabled"&lt;/span&gt;
git credential fill &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOT&lt;/span&gt;&lt;span class="sh"&gt;'
url=https://example.com/test-group/test-repo2.git
username=user2
&lt;/span&gt;&lt;span class="no"&gt;EOT
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>cicd</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
