<?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>OpenSSH &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/openssh/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Mon, 02 Nov 2020 13:50:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Visual C#: GUI front-end for OpenSSH in Windows</title>
		<link>https://blog.andreev.it/2019/03/149-visual-c-gui-front-end-for-openssh-in-windows/</link>
					<comments>https://blog.andreev.it/2019/03/149-visual-c-gui-front-end-for-openssh-in-windows/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Mon, 04 Mar 2019 19:48:10 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[front-end]]></category>
		<category><![CDATA[OpenSSH]]></category>
		<category><![CDATA[Visual C#]]></category>
		<guid isPermaLink="false">https://blog.andreev.it/?p=4573</guid>

					<description><![CDATA[As of late 2018, Windows 10 and Windows 2019 come up with OpenSSH installed.&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>As of late 2018, Windows 10 and Windows 2019 come up with OpenSSH installed. I had to use OpenSSH in some of the scripts at work, but managing the connections became difficult. So, I created a small .NET program that manages SSH connections. It&#8217;s a very simple SSH GUI front-end for OpenSSH. It&#8217;s not meant to be a replacement for putty or any other SSH terminal programs.<br />
In case you get an error that your PEM certificate is wide open, change the permissions on that file. Do this from a command prompt, not from a Power Shell prompt.</p>
<pre class="brush: bash; title: ; notranslate">
set key=&quot;c:\folder\mykey.pem&quot;
cmd /c icacls %key% /c /t /inheritance:d
cmd /c icacls %key% /c /t /grant %username%:F
cmd /c icacls %key%  /c /t /remove Administrator BUILTIN\Administrators BUILTIN Everyone System Users &quot;Authenticated Users&quot;
cmd /c icacls %key%
</pre>
<p>Here is the <a href="https://github.com/klimenta/pusshy" rel="noopener noreferrer" target="_blank">link</a> to the GitHub repo.<br />
Here is a screenshot.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2019/03/P126-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2019/03/P126-01.png" alt="" width="699" height="160" class="aligncenter size-full wp-image-8461" srcset="https://blog.andreev.it/wp-content/uploads/2019/03/P126-01.png 699w, https://blog.andreev.it/wp-content/uploads/2019/03/P126-01-300x69.png 300w, https://blog.andreev.it/wp-content/uploads/2019/03/P126-01-585x134.png 585w" sizes="(max-width: 699px) 100vw, 699px" /></a><br />
Here is the C# source. Click + to expand. </p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">
using System;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;

namespace pusshy
{
    public partial class frmpusshy : Form
    {
        //It holds the name of the header column when a cell is right-clicked
        //Used for hiding columns
        string strColumnHeader; 
        //When a user hits enter, the next selected cell is on the right, not the bottom one
        //It allows horizontal scrolling when typing, not vertical
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            int intColumn = gridHosts.CurrentCell.ColumnIndex;
            int intRow = gridHosts.CurrentCell.RowIndex;
            if (keyData == Keys.Enter)
            {
                if (intColumn == gridHosts.Columns.Count - 1)
                {
                    gridHosts.Rows.Add();
                    gridHosts.CurrentCell = gridHosts&#x5B;0, intRow + 1];
                }
                else
                {
                    gridHosts.CurrentCell = gridHosts&#x5B;intColumn + 1, intRow];
                }
                return true;
            }
            else
                return base.ProcessCmdKey(ref msg, keyData);
        }

        public frmpusshy()
        {
            InitializeComponent();
        }

        private void frmpusshy_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Save the current size and position of the window
            //Used to remember these settings when the program is started next time
            Properties.Settings.Default&#x5B;&quot;Location&quot;] = this.Location;
            Properties.Settings.Default&#x5B;&quot;Size&quot;] = this.Size;
            Properties.Settings.Default.Save();
            //The local app data folder where settings and the data will be saved
            var strLocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //The data is in pusshy.csv file under C:\Users\&lt;username&gt;\AppData\Local\pusshy
            var strFileName = strLocalAppData + &quot;/pusshy/&quot; + &quot;pusshy.csv&quot;;
            string strCellValue;
            //Open the file for saving
            StreamWriter csvFileWriter = new StreamWriter(strFileName, false);
            int intColumnCount = gridHosts.ColumnCount - 1;
            int intColCount = gridHosts.Columns.Count;
            //Iterate through the grid and save
            foreach (DataGridViewRow dataRowObject in gridHosts.Rows)
            {
                if (!dataRowObject.IsNewRow)
                {
                    string strDataFromGrid = &quot;&quot;;                    
                    for (int i = 0; i &lt;= intColumnCount; i++)
                    {
                        try
                        {
                            strCellValue = dataRowObject.Cells&#x5B;i].Value.ToString();
                        }
                        //If the cell has no value, replace it with blank string instead of null
                        catch (System.NullReferenceException exception)
                        {
                            strCellValue = &quot;&quot;;
                        }
                        //Create a comma separated line
                        if (i != 0)
                        {
                            strDataFromGrid = strDataFromGrid + ',' + strCellValue;
                        }
                        else
                        {
                            strDataFromGrid = strCellValue;
                        }
                    }
                    csvFileWriter.WriteLine(strDataFromGrid);
                }
            }
            csvFileWriter.Flush();
            csvFileWriter.Close();
        }
        //Tag the whole row if there is a password in the password column (column=2). Used to hide password cells
        private void gridHosts_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {            
            if (gridHosts.CurrentRow.Tag != null &amp;&amp; gridHosts.CurrentCell.ColumnIndex == 2)
            {
                e.Control.Text = gridHosts.CurrentRow.Tag.ToString();
            }
        }
        //Replace the text in the password cell (column=2) with dots
        private void gridHosts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 2 &amp;&amp; e.Value != null)
            {                
                gridHosts.Rows&#x5B;e.RowIndex].Tag = e.Value;
                e.Value = new String('\u25CF', e.Value.ToString().Length);
            }
        }
        //Right-click on row header or column header
        private void gridHosts_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                var hit = gridHosts.HitTest(e.X, e.Y);
                var intCurrentColumnIndex = hit.ColumnIndex;
                //If the user right-clicks the column header display this menu
                if ((hit.Type == DataGridViewHitTestType.ColumnHeader))
                {
                    strColumnHeader = gridHosts.Columns&#x5B;intCurrentColumnIndex].HeaderText;
                    menuRightColumnClick.Show(MousePosition);
                }
                //If the user right-clicks the column header display this menu
                if ((hit.Type == DataGridViewHitTestType.RowHeader))
                {
                    menuRightRowClick.Show(MousePosition);
                }
            }
        }
        //Hide the column that was selected
        private void hideToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gridHosts.Columns&#x5B;strColumnHeader].Visible = false;
        }       
        //Delete a row
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in gridHosts.SelectedRows)
            {
                try
                {
                    gridHosts.Rows.Remove(row);
                }
                //Can't delete the bottom row. Catch the exception
                catch (InvalidOperationException exception)
                {
                    return;
                }
            }
        }

        private void frmpusshy_Load(object sender, EventArgs e)
        {
            //The local app data folder where settings and the data will be saved
            var strLocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //The data is in pusshy.csv file under C:\Users\&lt;username&gt;\AppData\Local\pusshy
            var strFileName = strLocalAppData + &quot;/pusshy/&quot; + &quot;pusshy.csv&quot;;
            if (!File.Exists(strFileName))
            {
                return;
            }   
            //Clear the grid and load the pusshy.csv file
            gridHosts.Rows.Clear();
            StreamReader fileReader = new StreamReader(strFileName, false);
            int i = 0;
            while (fileReader.Peek() != -1)
            {
                var fileRow = fileReader.ReadLine();
                var fileDataField = fileRow.Split(',');
                gridHosts.Rows.Add(fileDataField);
                //var rd = fileDataField&#x5B;2];                
                i++;
            }
            fileReader.Dispose();
            fileReader.Close();
            //Change the size and the position of the application on load
            //With the settings that were saved last time the app was used
            this.Location = Properties.Settings.Default.Location;
            this.Size = Properties.Settings.Default.Size;
        }
        //When the user chooses Show All, all hidden columns will become visible
        private void showAllToolStripMenuItem_Click(object sender, EventArgs e)
        {            
            foreach (DataGridViewColumn column in gridHosts.Columns)
            {
                string strHeaderCaptionText = column.HeaderText;
                gridHosts.Columns&#x5B;strHeaderCaptionText].Visible = true;
            }                    
        }
        //When the user double-clicks a cell, launch the terminal
        private void gridHosts_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string strCommand = &quot;&quot;;
            int intRowIndex = gridHosts.CurrentCell.RowIndex;  
            //Get all values from the row
            string strHost = gridHosts.Rows&#x5B;intRowIndex].Cells&#x5B;0].Value.ToString();
            string strLogin = gridHosts.Rows&#x5B;intRowIndex].Cells&#x5B;1].Value.ToString();
            string strPwd = gridHosts.Rows&#x5B;intRowIndex].Cells&#x5B;2].Value.ToString();
            string strCert = gridHosts.Rows&#x5B;intRowIndex].Cells&#x5B;3].Value.ToString();
            //If the password cell is empty, start the terminal with certificate
            if (strPwd == &quot;&quot;)
            {
                strCommand = &quot;\&quot;C:/windows/sysnative/OpenSSH/ssh.exe\&quot; -l &quot; + strLogin + &quot; &quot; + &quot;-i &quot; + strCert + &quot; &quot; + strHost;
            } else
            //Or without password
            {
                strCommand = &quot;\&quot;C:/windows/sysnative/OpenSSH/ssh.exe\&quot; -l &quot; + strLogin + &quot; &quot; + strHost;
            }
            Process.Start(&quot;powershell.exe&quot;, strCommand);            
        }
    }
}
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2019/03/149-visual-c-gui-front-end-for-openssh-in-windows/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
