<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>git &#8211; Matthew Petroff</title>
	<atom:link href="https://mpetroff.net/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>https://mpetroff.net</link>
	<description>mpetroff.net</description>
	<lastBuildDate>Tue, 31 Dec 2024 01:31:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Making Git prompt for SSH username</title>
		<link>https://mpetroff.net/2024/12/making-git-prompt-for-ssh-username/</link>
					<comments>https://mpetroff.net/2024/12/making-git-prompt-for-ssh-username/#respond</comments>
		
		<dc:creator><![CDATA[Matthew Petroff]]></dc:creator>
		<pubDate>Tue, 31 Dec 2024 01:21:17 +0000</pubDate>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[username]]></category>
		<guid isPermaLink="false">https://mpetroff.net/?p=3886</guid>

					<description><![CDATA[In what seems to be an unusual configuration&#8212;as I was unable to find any information on how to do it&#8212;I had a need to make Git prompt for an SSH username. The repositories in question are on a shared computer, &#8230; <a href="https://mpetroff.net/2024/12/making-git-prompt-for-ssh-username/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p><span class="dropcap">I</span>n what seems to be an unusual configuration&mdash;as I was unable to find any information on how to do it&mdash;I had a need to make Git prompt for an SSH username. The repositories in question are on a shared computer, but the host for the remote copies requires individual user authentication using a password and a TOTP code. A crude solution was to set <tt>GIT_SSH_COMMAND='ssh -l $USER'</tt>, but this requires the user to remember to run, e.g., <tt>USER=username git pull</tt>, although this can be helped by setting <tt>USER='Prefix_git_with_"USER=yourusername"!!!!!!!!'</tt> in <tt>.bashrc</tt>. After much trial and error, I arrived at the solution of setting the <tt>GIT_SSH</tt> environment variable in <tt>.bashrc</tt> to point at the following shell script:</p>
<pre>#!/bin/bash
# Make Git prompt for SSH username
# M. Petroff, 2024-12
if [[ $1 = "-G" ]]
then
  # Handle Git's SSH variant test
  ssh "$@"
else
  # Prompt for username
  read -p "Username: " user &lt;/dev/tty
  ssh -l "$user" "$@"
fi
</pre>
<p>There are two peculiarities here to keep in mind. First, <tt>stdin</tt> and <tt>stdout</tt> cannot be used, so input redirection needs to be used with <tt>read</tt> to get input directly from the terminal (<tt>/dev/tty</tt>), similar to what <a href="https://unix.stackexchange.com/a/171841">SSH itself does</a>; with the <tt>-p</tt> flag, <tt>read</tt> writes to <tt>stderr</tt>, which is okay. With this resolved, there were mysterious issues with either the username prompt being displayed twice or with needing to press &#8220;enter&#8221; to see the prompt, depending on the exact details of the then work-in-progress script. I eventually realized this was due to Git&#8217;s SSH variant checking, which first calls the <tt>GIT_SSH</tt> command with the <tt>-G</tt> argument to figure out which variant of SSH is in use. While this check can be avoided by setting <tt>GIT_SSH_VARIANT</tt> explicitly, it was easy enough to handle the check in the shell script.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mpetroff.net/2024/12/making-git-prompt-for-ssh-username/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Content Delivery Network via Amazon Web Services: CloudFront: cdn0.mpetroff.net
Minified using Disk

Served from: mpetroff.net @ 2026-03-30 09:44:30 by W3 Total Cache
-->