<?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>ssh - Hard Wired</title>
	<atom:link href="https://www.hardwired.dev/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.hardwired.dev</link>
	<description></description>
	<lastBuildDate>Wed, 25 Sep 2024 12:11:43 +0000</lastBuildDate>
	<language>cs</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.hardwired.dev/wp-content/uploads/2022/10/android-chrome-256x256-1-150x150.png</url>
	<title>ssh - Hard Wired</title>
	<link>https://www.hardwired.dev</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>SSH připojení pomocí ESP32</title>
		<link>https://www.hardwired.dev/2024/09/25/ssh-pripojeni-pomoci-esp32/</link>
		
		<dc:creator><![CDATA[John Doe]]></dc:creator>
		<pubDate>Wed, 25 Sep 2024 12:09:47 +0000</pubDate>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[IOT]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[esp32]]></category>
		<category><![CDATA[espressif]]></category>
		<category><![CDATA[home-automation]]></category>
		<category><![CDATA[iot]]></category>
		<category><![CDATA[libssh-esp32]]></category>
		<category><![CDATA[platformio]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[wifi]]></category>
		<guid isPermaLink="false">https://www.hardwired.dev/?p=2356</guid>

					<description><![CDATA[<p>V dnešním článku se podíváme na to, jak se z ESP32 development boardu připojit pomocí SSH ke vzdálenému počítači. Pro &#62;&#62;&#62;</p>
<p>The post <a href="https://www.hardwired.dev/2024/09/25/ssh-pripojeni-pomoci-esp32/">SSH připojení pomocí ESP32</a> first appeared on <a href="https://www.hardwired.dev">Hard Wired</a>.</p>]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>V dnešním článku se podíváme na to, jak se z <a href="https://vi.aliexpress.com/item/1005001621773806.html">ESP32 development boardu</a> připojit pomocí <a href="https://cs.wikipedia.org/wiki/Secure_Shell">SSH</a> ke vzdálenému počítači.</p>
<p>Pro vývoj je použito <a href="https://platformio.org/">PlatformIO</a>.</p>
<h1>platformio.ini</h1>
<pre><code class="language-ini">[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps = ewpa/LibSSH-ESP32@^4.2.0</code></pre>
<h1>main.cpp</h1>
<p>Jediná externí závislost je <code>libssh-esp32</code>. </p>
<pre><code class="language-cpp">#include &lt;Arduino.h&gt;
#include &lt;WiFi.h&gt;
#include &lt;libssh_esp32.h&gt;
#include &quot;libssh_esp32_config.h&quot;
#include &lt;libssh/libssh.h&gt;
#include &lt;vector&gt;
#include &lt;string&gt;</code></pre>
<p>Budeme potřebovat SSID WiFi sítě a heslo.</p>
<pre><code class="language-cpp">const char *ssid = &quot;ssid-vasi-wifi&quot;;
const char *password = &quot;vase-nejtajnejsi-heslo&quot;;</code></pre>
<p>Potřebujeme nastavit přihlašovací údaje pro SSH a příkaz který po přihlášení provedeme.</p>
<pre><code class="language-cpp">const int ssh_port = 22;
const char *ssh_username = &quot;pi&quot;;
const char *ssh_password = &quot;super-tajne-heslo&quot;;
const char *ssh_command = &quot;ls -l&quot;;</code></pre>
<p>Dále seznam IP adres serverů na které se chceme připojit.</p>
<pre><code class="language-cpp">std::vector&lt;std::string&gt; server_ips = {
    &quot;192.168.1.254&quot;,
};</code></pre>
<p>Vytvoříme funkci pro připojení k WiFi. Na konci vypíšeme do konzole MAC adresu přístupového bodu, ke kterému jsme se připojili.</p>
<pre><code class="language-cpp">void connectToWiFi()
{
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(1000);
        Serial.println(&quot;Connecting to WiFi..&quot;);
    }
    Serial.print(&quot;Připojeno k AP s MAC: &quot;);
    Serial.println(WiFi.BSSIDstr());
}</code></pre>
<p>Ted ta nejdelší část. Funkce co vytvoří SSH spojení, provede příkaz a výsledek vypíše na standardní výstup. Funkce si po sobě uklízí.</p>
<pre><code class="language-cpp">/**
 * Execute SSH Command
 *
 * @param ip Server IP
 * @param username SSH Username
 * @param password SSH Password
 * @param command Command to execute
 */
void executeSSHCommand(const char *ip, const char *username, const char *password, const char *command)
{
    // Create a new SSH session
    ssh_session session = ssh_new();
    if (session == NULL)
    {
        Serial.println(&quot;Failed to create SSH session&quot;);
        return;
    }

    // Set SSH options for the session
    ssh_options_set(session, SSH_OPTIONS_HOST, ip);
    ssh_options_set(session, SSH_OPTIONS_USER, username);

    // Connect to SSH server
    int rc = ssh_connect(session);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to connect to SSH server&quot;);
        return;
    }

    // Verify the server&#039;s identity
    rc = ssh_userauth_password(session, NULL, password);
    if (rc != SSH_AUTH_SUCCESS)
    {
        Serial.println(&quot;Failed to authenticate&quot;);
        return;
    }

    // Create a new SSH channel
    ssh_channel channel = ssh_channel_new(session);
    if (channel == NULL)
    {
        Serial.println(&quot;Failed to create SSH channel&quot;);
        return;
    }

    // Open a new SSH session
    rc = ssh_channel_open_session(channel);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to open SSH session&quot;);
        return;
    }

    // Execute the command
    rc = ssh_channel_request_exec(channel, command);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to execute command&quot;);
        return;
    }

    // Read the output of the command
    char buffer[256];
    int nbytes; // Number of bytes read
    nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
    while (nbytes &gt; 0)
    {
        if (write(1, buffer, nbytes) != nbytes) // Write to stdout
        {
            Serial.println(&quot;Failed to write to stdout&quot;);
            return;
        }
        nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
    }

    // Check if there was an error reading from the channel
    if (nbytes &lt; 0)
    {
        Serial.println(&quot;Failed to read from SSH channel&quot;);
        return;
    }

    // Send EOF and close the channel
    ssh_channel_send_eof(channel);

    // Close the channel
    ssh_channel_close(channel);

    // Free the channel
    ssh_channel_free(channel);

    // Disconnect the session
    ssh_disconnect(session);

    // Free the session
    ssh_free(session);
}</code></pre>
<p>Teď potřebujeme funkci která provede SSH příkaz pro všechny naše servery, které jsou definované v <code>server_ips</code>.</p>
<pre><code class="language-cpp">/**
 * Execute SSH Command on all servers
 * 
 * @param username SSH Username
 * @param password SSH Password
 * @param command Command to execute
 */
void executeSSHCommandOnAllServers(const char *username, const char *password, const char *command)
{
    for (std::string ip : server_ips)
    {
        executeSSHCommand(ip.c_str(), username, password, command);
    }
}</code></pre>
<p>Teď už jen zbývá provést vše při startu ESPčka.</p>
<pre><code class="language-cpp">void setup()
{
    Serial.begin(115200);
    while (!Serial)
    {
        ; // Wait for serial to be ready
    }

    connectToWiFi();
    ssh_init();
    executeSSHCommandOnAllServers(ssh_username, ssh_password, ssh_command);
}</code></pre>
<p>Hlavní smyčku programu pro tento příklad necháme odpočívat.</p>
<pre><code class="language-cpp">void loop()
{
    delay(1000); // Delay for 1 second
}</code></pre>
<p>To je vše. Po kompilaci, nahrání kódu a spuštění ESPčka se připojí k WiFi a poté provede SSH připojení na zadané IP adresy a provede <code>ls -l</code> příkaz. Ten vypíše do konzole.</p>
<h1>main.cpp full</h1>
<pre><code class="language-cpp">#include &lt;Arduino.h&gt;
#include &lt;WiFi.h&gt;
#include &lt;libssh_esp32.h&gt;
#include &quot;libssh_esp32_config.h&quot;
#include &lt;libssh/libssh.h&gt;
#include &lt;vector&gt;
#include &lt;string&gt;

// WiFi Credentials
const char *ssid = &quot;ssid-vasi-wifi&quot;;
const char *password = &quot;vase-nejtajnejsi-heslo&quot;;

// SSH Credentials
const int ssh_port = 22;
const char *ssh_username = &quot;pi&quot;;
const char *ssh_password = &quot;super-tajne-helso&quot;;
const char *ssh_command = &quot;ls -l&quot;;

// Server IPs List
std::vector&lt;std::string&gt; server_ips = {
    &quot;192.168.1.254&quot;,
};

/**
 * Connect to WiFi
 */
void connectToWiFi()
{
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(1000);
        Serial.println(&quot;Connecting to WiFi..&quot;);
    }
    Serial.print(&quot;Připojeno k AP s MAC: &quot;);
    Serial.println(WiFi.BSSIDstr());
}

/**
 * Execute SSH Command
 *
 * @param ip Server IP
 * @param username SSH Username
 * @param password SSH Password
 * @param command Command to execute
 */
void executeSSHCommand(const char *ip, const char *username, const char *password, const char *command)
{
    // Create a new SSH session
    ssh_session session = ssh_new();
    if (session == NULL)
    {
        Serial.println(&quot;Failed to create SSH session&quot;);
        return;
    }

    // Set SSH options for the session
    ssh_options_set(session, SSH_OPTIONS_HOST, ip);
    ssh_options_set(session, SSH_OPTIONS_USER, username);

    // Connect to SSH server
    int rc = ssh_connect(session);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to connect to SSH server&quot;);
        return;
    }

    // Verify the server&#039;s identity
    rc = ssh_userauth_password(session, NULL, password);
    if (rc != SSH_AUTH_SUCCESS)
    {
        Serial.println(&quot;Failed to authenticate&quot;);
        return;
    }

    // Create a new SSH channel
    ssh_channel channel = ssh_channel_new(session);
    if (channel == NULL)
    {
        Serial.println(&quot;Failed to create SSH channel&quot;);
        return;
    }

    // Open a new SSH session
    rc = ssh_channel_open_session(channel);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to open SSH session&quot;);
        return;
    }

    // Execute the command
    rc = ssh_channel_request_exec(channel, command);
    if (rc != SSH_OK)
    {
        Serial.println(&quot;Failed to execute command&quot;);
        return;
    }

    // Read the output of the command
    char buffer[256];
    int nbytes; // Number of bytes read
    nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
    while (nbytes &gt; 0)
    {
        if (write(1, buffer, nbytes) != nbytes) // Write to stdout
        {
            Serial.println(&quot;Failed to write to stdout&quot;);
            return;
        }
        nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
    }

    // Check if there was an error reading from the channel
    if (nbytes &lt; 0)
    {
        Serial.println(&quot;Failed to read from SSH channel&quot;);
        return;
    }

    // Send EOF and close the channel
    ssh_channel_send_eof(channel);

    // Close the channel
    ssh_channel_close(channel);

    // Free the channel
    ssh_channel_free(channel);

    // Disconnect the session
    ssh_disconnect(session);

    // Free the session
    ssh_free(session);
}

/**
 * Execute SSH Command on all servers
 *
 * @param username SSH Username
 * @param password SSH Password
 * @param command Command to execute
 */
void executeSSHCommandOnAllServers(const char *username, const char *password, const char *command)
{
    for (std::string ip : server_ips)
    {
        executeSSHCommand(ip.c_str(), username, password, command);
    }
}

void setup()
{
    Serial.begin(115200);
    while (!Serial)
    {
        ; // Wait for serial to be ready
    }

    connectToWiFi();
    ssh_init();
    executeSSHCommandOnAllServers(ssh_username, ssh_password, ssh_command);
}

void loop()
{
    delay(1000); // Delay for 1 second
}
</code></pre>

<div class="twitter-share"><a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.hardwired.dev%2F2024%2F09%2F25%2Fssh-pripojeni-pomoci-esp32%2F&#038;via=hessevalentino" class="twitter-share-button">Tweet</a></div><p>The post <a href="https://www.hardwired.dev/2024/09/25/ssh-pripojeni-pomoci-esp32/">SSH připojení pomocí ESP32</a> first appeared on <a href="https://www.hardwired.dev">Hard Wired</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Gitea a první soukromý repozitář</title>
		<link>https://www.hardwired.dev/2024/09/16/gitea-a-prvni-soukromy-repozitar/</link>
		
		<dc:creator><![CDATA[John Doe]]></dc:creator>
		<pubDate>Sun, 15 Sep 2024 22:15:31 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[gitea]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[self-hosted]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">https://www.hardwired.dev/?p=2348</guid>

					<description><![CDATA[<p>Článek navazuje na Gitea v Dockeru s daty na Synology a Gitea na veřejné subdoméně. Tentokrát si ukážeme, jak vytvořit &#62;&#62;&#62;</p>
<p>The post <a href="https://www.hardwired.dev/2024/09/16/gitea-a-prvni-soukromy-repozitar/">Gitea a první soukromý repozitář</a> first appeared on <a href="https://www.hardwired.dev">Hard Wired</a>.</p>]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Článek navazuje na <a href="https://www.hardwired.dev/2024/09/14/gitea-v-dockeru-s-daty-na-synology/">Gitea v Dockeru s daty na Synology</a> a <a href="https://www.hardwired.dev/2024/09/15/gitea-na-verejne-subdomene/">Gitea na veřejné subdoméně</a>. Tentokrát si ukážeme, jak vytvořit nový soukromý repozitář a posílat do něj změny.</p>
<h1>Předpoklady</h1>
<ul>
<li>Máme funkční Giteu na vlastní subdoméně, do které se dokážeme přihlásit</li>
<li>Byly provedeny všechny kroky z předchozích návodů</li>
<li>Článek se zaměřuje na Windows ale na Linuxu to bude to samé nebo hodně podobné</li>
<li>Na počítači máme funkční SSH a <a href="https://git-scm.com/">GIT</a>.</li>
</ul>
<h1>Vytvoření soukromého repozitáře</h1>
<p>Přihlásíme se do naší Gitey. <code>Pluskem</code> zvolíme nový repozitář. Zadáme název repozitáře, <code>soukromy-repo-na-smazani</code>. Vybereme <code>Nastavit repozitář jako soukromý</code> a potvrdíme. Vytvoří se prázdný repozitář.</p>
<h1>Vytvoření SSH klíče</h1>
<p>Pro komunikaci s repozitářem budeme používat <a href="https://cs.wikipedia.org/wiki/Secure_Shell">SSH</a>. Budeme muset vytvořit pár klíčů, soukromý a veřejný. Soukromý bude u nás na počítači a veřejný budeme nahrajeme k repozitáři, jako přístupový.</p>
<p>Ujistíme se že v <code>c:\Users\&lt;username&gt;</code> máme složku <code>.ssh</code>. Poté v terminálu zadáme příkaz na vygenerování klíče pro přístup do Gitea. </p>
<p><code>ssh-keygen -t rsa -b 4096 -C &quot;&lt;váš email&gt;&quot; -f ~/.ssh/gitea-example-com</code></p>
<p>To ve složce <code>.ssh</code> vytvoří dva soubory. <code>gitea-example-com</code> a <code>gitea-example-com.pub</code>. Ten druhý musíme nahrát k repozitáři.</p>
<h1>Přidání klíče do Gitea repozitáře</h1>
<p>Otevřeme si repozitář. <code>Nastavení &gt; Klíče pro nasazení &gt; Přidat klič pro nasazení</code>. Pojmenujeme si ho, například <code>Domácí klíč</code>. A obsah <code>gitea-example-com.pub</code> zkopírujeme do pole <code>Obsah</code>. Nesmíme zapomenout zaškrtnout volbu <code>Povolit zápis</code> a potvrdit.</p>
<h1>Nastavení SSH na počítači</h1>
<p>Pokud ve složce <code>c:\Users\&lt;username&gt;\.ssh</code> nemáte soubor <code>config</code>, vytvořte ho a přidejte následující.</p>
<pre><code>Host gitea.example.com
  HostName gitea.example.com
  User git
  Port 222
  IdentityFile c:\Users\&lt;username&gt;\.ssh\gitea-example-com
  IdentitiesOnly yes</code></pre>
<p>Pro hosta <code>gitea.example.com</code> se nastaví odpovídající <code>host name</code>, <code>uživatel</code>, <code>port</code> pro připojení a <code>cesta k privátnímu klíči</code>. Volba <code>IdentitiesOnly</code> zajistí, že pro konkrétního hosta se použijí parametry, které jsou nastaveny.</p>
<h1>Připojení repozitáře</h1>
<p>Buď můžete připojit už existující repozitář z vašeho počítače, nebo vytvoříte nový. Vytvoříme nový.</p>
<p>Vytvořte složku kde bude nový repozitář. Obecně se pojmenuje názvem repozitáře co jsme vytvořili na naší Gitea.</p>
<pre><code class="language-shell">mkdir soukromy-repo-na-smazani</code></pre>
<p>Přesuneme se do něj.</p>
<pre><code class="language-shell">cd soukromy-repo-na-smazani</code></pre>
<p>Inicializujeme prázdný repozitář.</p>
<pre><code class="language-shell">git init</code></pre>
<p>Vytvoříme první soubor <code>README.md</code>.</p>
<pre><code class="language-shell">touch README.md</code></pre>
<p>Vytvoříme hlavní větev <code>main</code>.</p>
<pre><code class="language-shell">git checkout -b main</code></pre>
<p>Přidáme soubor <code>README.md</code> do <code>git</code> repozitáře.</p>
<pre><code class="language-shell">git add README.md</code></pre>
<p>Vytvoříme první <code>commit</code>.</p>
<pre><code class="language-shell">git commit -m &quot;První commit&quot;</code></pre>
<p>Napojíme náš repozitář z Gitea.</p>
<pre><code class="language-shell">git remote add origin git@gitea.example.com:&lt;gitea username&gt;/soukromy-repo-na-smazani.git</code></pre>
<p>Odešleme změny do vzdáleného repozitáře.</p>
<pre><code class="language-shell">git push -u origin main</code></pre>
<p>Když se nyní podíváme do repozitáře na <code>gitea.example.com</code>, uvidíme náš první <code>commit</code>.</p>

<div class="twitter-share"><a href="https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.hardwired.dev%2F2024%2F09%2F16%2Fgitea-a-prvni-soukromy-repozitar%2F&#038;via=hessevalentino" class="twitter-share-button">Tweet</a></div><p>The post <a href="https://www.hardwired.dev/2024/09/16/gitea-a-prvni-soukromy-repozitar/">Gitea a první soukromý repozitář</a> first appeared on <a href="https://www.hardwired.dev">Hard Wired</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
