tag:blogger.com,1999:blog-37854850694620127282024-02-20T12:32:52.868-08:00Jordan's Tech SpotJordanhttp://www.blogger.com/profile/14001679547566992736noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3785485069462012728.post-11127455008725708152018-02-08T01:47:00.003-08:002018-03-03T06:05:21.034-08:00Make scp autocomplete server names and file/folders names on Ubuntu 16.04<div dir="ltr" style="text-align: left;" trbidi="on">
I was struggling to make <b>scp</b> auto-complete servers names but also complete <u>local</u> files names under Ubuntu bash.<br />
<br />
For some strange reason, out of the box solutions just didn't work, I could make the server completion work or the local files completion work but not both.<br />
And I'm not even talking about remote file names over SSH, just local file names.<br />
<br />
Installing auto-complete on Ubuntu if not already there:<br />
<br />
<a href="https://unix.stackexchange.com/questions/136351/autocomplete-server-names-for-ssh-and-scp/335143">https://unix.stackexchange.com/questions/136351/autocomplete-server-names-for-ssh-and-scp/335143</a><br />
<br />
Replace <span style="color: blue;">/etc/bash_completion.d/ssh</span> with the following content:<br />
<br />
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="color: white; font-family: "consolas"; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="color: white; font-family: "consolas"; font-size: 10pt;"> </span><span style="color: #444444;"><span class="SpellE"><span class="GramE"><span style="font-family: "consolas"; font-size: 10pt;">ssh</span></span></span><span class="GramE"><span style="font-family: "consolas"; font-size: 10pt;">(</span></span><span style="font-family: "consolas"; font-size: 10pt;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> local cur <span class="SpellE">prev</span> opts<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> COMPREPLY<span class="GramE">=(</span>)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> cur="${COMP_WORDS[COMP_CWORD]}"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <span class="SpellE">prev</span>="${COMP_WORDS[COMP_CWORD-1]}"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> opts=$(grep '^Host' ~/.<span class="SpellE">ssh</span>/config | grep -v '<span class="GramE">[?*</span>]' | cut -d ' ' -f 2-)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="color: #444444; font-family: "consolas"; font-size: 10pt;"> _</span><span class="SpellE" style="color: #444444; font-family: "consolas"; font-size: 10pt;">longopt</span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> RESULT="$COMPREPLY $opts"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> COMPREPLY<span class="GramE">=( $</span>(<span class="SpellE">compgen</span> -W "$RESULT" -- ${cur}) )<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="color: #444444; font-family: "consolas"; font-size: 10pt;"> if [[ "$cur" == -</span><span class="GramE" style="color: #444444; font-family: "consolas"; font-size: 10pt;">* ]</span><span style="color: #444444; font-family: "consolas"; font-size: 10pt;">]; then</span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> COMPREPLY<span class="GramE">=( $</span>( <span class="SpellE">compgen</span> -W "$( $1 --help 2>&1 | \<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <span class="SpellE">sed</span> -ne 's<span class="GramE">/.*</span>\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\1/p' | sort -u)" \<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> -- "$cur<span class="GramE">" )</span> )<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> [[ $COMPREPLY == *<span class="GramE">= ]</span>] && <span class="SpellE">compopt</span> -o <span class="SpellE">nospace</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <span class="SpellE">elif</span> [[ "$1" == @(<span class="SpellE">mk|<span class="GramE">rm</span></span><span class="GramE">)<span class="SpellE">dir</span></span> ]]; then<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> _<span class="SpellE">filedir</span> -d<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> _<span class="SpellE">filedir</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> fi<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> return 0<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> complete -F _<span class="SpellE">ssh</span> <span class="SpellE">ssh</span><o:p></o:p></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span style="color: #444444;"> complete -F _<span class="SpellE">ssh</span> <span class="SpellE">scp</span></span></span></div>
<div class="MsoNormal" style="background: rgb(217, 217, 217); font-family: Calibri, sans-serif; font-size: 11pt; line-height: normal; margin: 0in 0in 0.0001pt;">
<span style="font-family: "consolas"; font-size: 10pt;"><span class="SpellE"><br /></span></span></div>
<br />
<div>
Enjoy !</div>
<style type="text/css">
@page { margin: 0.79in }
p { margin-bottom: 0.1in; direction: ltr; color: #00000a; line-height: 120%; text-align: left; orphans: 2; widows: 2 }
p.western { font-family: "Courier New", serif; font-size: 10pt; so-language: en-US }
p.cjk { font-family: "Calibri"; font-size: 10pt; so-language: en-US }
p.ctl { font-family: "Arial"; font-size: 11pt; so-language: he-IL }
a.western:visited { so-language: en-US }
a.cjk:visited { so-language: en-US }
a.ctl:visited { so-language: he-IL }
a:link { color: #0563c1 }
</style><style type="text/css">
@page { margin: 0.79in }
p { margin-bottom: 0.1in; direction: ltr; color: #00000a; line-height: 120%; text-align: left; orphans: 2; widows: 2 }
p.western { font-family: "Courier New", serif; font-size: 10pt; so-language: en-US }
p.cjk { font-family: "Calibri"; font-size: 10pt; so-language: en-US }
p.ctl { font-family: "Arial"; font-size: 11pt; so-language: he-IL }
a.western:visited { so-language: en-US }
a.cjk:visited { so-language: en-US }
a.ctl:visited { so-language: he-IL }
a:link { color: #0563c1 }
</style><br />
<style type="text/css">
@page { margin: 0.79in }
p { margin-bottom: 0.1in; line-height: 120% }
a:link { so-language: zxx }
</style></div>
Jordanhttp://www.blogger.com/profile/14001679547566992736noreply@blogger.com0tag:blogger.com,1999:blog-3785485069462012728.post-44191654263963959722015-09-22T05:42:00.000-07:002015-10-17T00:20:29.539-07:00Making pageant load keys and passwords from command line.<div dir="ltr" style="text-align: left;" trbidi="on">
I have tried looking all over the place for a solution to load <b>pageant.exe</b> that will load my private keys using their passwords in an automated way and could not find one.<br />
<br />
Pageant by default knows how to read keys passed as parameters via command line but does not know how to receive the associated passwords belong to them.<br />
<br />
Therefore, I had created a patched version that knows how to handle the above.<br />
<br />
Usage:<br />
<br />
<b>pageant.exe -p file1_password file1.ppk -p file2__password file2.ppk</b><br />
<b><br /></b>
Link to download the patched pageant:<br />
<br />
<a href="http://www.herewenet.com/downloads/pageant_twee.exe">pageant.exe</a><br />
<br />
Hope that helps.<br />
<br />
<br />
<br /></div>
Jordanhttp://www.blogger.com/profile/14001679547566992736noreply@blogger.com2