<?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 &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 04:04:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>SSH &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>GitHub: Key is Already in Use</title>
		<link>https://myshittycode.com/2022/11/23/github-key-is-already-in-use/</link>
					<comments>https://myshittycode.com/2022/11/23/github-key-is-already-in-use/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 23 Nov 2022 14:12:50 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1974</guid>

					<description><![CDATA[<p>PROBLEM When trying to add a SSH key in GitHub, an error &#8220;Key is already in use&#8221; is thrown even though you signed into GitHub using a different user account. SOLUTION The error occurs when the same SSH key has been added to a different account. This typically happens when you already have an existing [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2022/11/23/github-key-is-already-in-use/">GitHub: Key is Already in Use</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p class="wp-block-paragraph">When trying to add a SSH key in GitHub, an error &#8220;Key is already in use&#8221; is thrown even though you signed into GitHub using a different user account.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="135" src="https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use-1024x135.png?x45560" alt="" class="wp-image-1975" srcset="https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use-1024x135.png 1024w, https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use-300x40.png 300w, https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use-768x102.png 768w, https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use-1536x203.png 1536w, https://myshittycode.com/wp-content/uploads/2022/11/github-key-in-use.png 1740w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">SOLUTION</h2>



<p class="wp-block-paragraph">The error occurs when <a href="https://docs.github.com/en/authentication/troubleshooting-ssh/error-key-already-in-use" target="_blank" rel="noopener">the same SSH key has been added to a different account</a>. This typically happens when you already have an existing personal GitHub account and you are trying to use the same SSH key in a work-related GitHub Enterprise account.</p>



<p class="wp-block-paragraph">The fix is to use a new SSH key. When generating the SSH key using <strong>ssh-keygen</strong>, remember NOT to override the existing ~/.ssh/id_rsa. Rather, use a different file path, such as ~/.ssh/id_rsa_github_enterprise. </p>



<p class="wp-block-paragraph">To ensure seamless integration when doing a git clone, add the following configuration in ~/.ssh/config.  </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Host github.com
  Hostname github.com
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-enterprise.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_github_enterprise
</pre></div>


<p class="wp-block-paragraph">The first block ensures it doesn&#8217;t break the existing GitHub connectivity using the default SSH key.</p>



<p class="wp-block-paragraph">The second block allows a different SSH key to be used when connecting to GitHub.  In order to leverage this configuration, the host name needs to be tweaked when doing a git clone.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
# Don&#039;t do this because this will use ~/.ssh/id_rsa
git clone git@github.com:shitty_user/shitty_repo.git 

# Do this instead to use the new SSH key
git clone git@github-enterprise.com:shitty_user/shitty_repo.git 
</pre></div>


<p class="wp-block-paragraph"></p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2022/11/23/github-key-is-already-in-use/">GitHub: Key is Already in Use</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2022/11/23/github-key-is-already-in-use/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1974</post-id>	</item>
		<item>
		<title>GCP: Pushing Codebase from IntelliJ IDEA to VM Instance</title>
		<link>https://myshittycode.com/2022/02/08/gcp-pushing-codebase-from-intellij-idea-to-vm-instance/</link>
					<comments>https://myshittycode.com/2022/02/08/gcp-pushing-codebase-from-intellij-idea-to-vm-instance/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 09 Feb 2022 01:14:01 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Google Cloud Platform]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IntelliJ IDEA]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1267</guid>

					<description><![CDATA[<p>OBJECTIVE To push codebase from IntelliJ IDEA (or any JetBrains products) on a local machine to a VM instance in Google Cloud Platform. To run the codebase remotely. WHY DO THIS You want to leverage all the power of a modern IDE on your 4K screen. You do not want to use remote desktop tools [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2022/02/08/gcp-pushing-codebase-from-intellij-idea-to-vm-instance/">GCP: Pushing Codebase from IntelliJ IDEA to VM Instance</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="objective">OBJECTIVE</h2>



<p class="wp-block-paragraph">To push codebase from IntelliJ IDEA (or any JetBrains products) on a local machine to a VM instance in Google Cloud Platform.</p>



<p class="wp-block-paragraph">To run the codebase remotely.</p>



<h2 class="wp-block-heading" id="why-do-this">WHY DO THIS</h2>



<p class="wp-block-paragraph">You want to leverage all the power of a modern IDE on your 4K screen.</p>



<p class="wp-block-paragraph">You do not want to use remote desktop tools such as VNC or NoMachine due to performance and screen lag problems.</p>



<p class="wp-block-paragraph">Your team members make fun of your VIM skills.</p>



<h2 class="wp-block-heading" id="solution">SOLUTION</h2>



<h3 class="wp-block-heading" id="configuring-vm-port-forwarding">Configuring VM Port Forwarding</h3>



<p class="wp-block-paragraph">Log into GCP.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
gcloud auth login
</pre></div>


<p class="wp-block-paragraph">Perform port forwarding over SSH using your running VM.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
# SYNTAX
gcloud compute ssh VM_NAME \
    --project PROJECT_ID \
    --zone ZONE \
    -- -NL LOCAL_PORT:localhost:REMOTE_PORT

# EXAMPLE
gcloud compute ssh shitty_vm \
    --project shitty_project \
    --zone us-central1-b \
    -- -NL 8888:localhost:22
</pre></div>


<p class="wp-block-paragraph">Note: If you choose to listen to local port 22, you will most likely to get this error because your local SSH server may already be using it:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 22
Could not request local forwarding.
</pre></div>


<p class="wp-block-paragraph">If this is your first SSH into your VM, you will be prompted to create the SSH key pair. In this case, keep pressing the &#8220;Enter&#8221; key until it is created.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
WARNING: The private SSH key file for gcloud does not exist.
WARNING: The public SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/shitty_user/.ssh/google_compute_engine.
Your public key has been saved in /Users/shitty_user/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:gmwGL9bfJLi/FYnebZLL0vVBYoZ3XeT/ivSSFCmiRT8 shitty_user@shitty_machine
The key&#039;s randomart image is:
+---&#x5B;RSA 3072]----+
|               ..|
|        .      ..|
|  .    . o   o ..|
|   = o .+.E = . .|
|  o O +oS= * .  .|
| . + +.* +. o   .|
|    . o.*.oo.o  .|
|     ..o.+ .+o . |
|      ooo   ..o  |
+----&#x5B;SHA256]-----+
External IP address was not found; defaulting to using IAP tunneling.
Writing 3 keys to /Users/shitty_user/.ssh/google_compute_known_hosts
</pre></div>


<p class="wp-block-paragraph">Upon a successful port forwarding, the command will hang with the following text:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
External IP address was not found; defaulting to using IAP tunneling.
Existing host keys found in /Users/shitty_user/.ssh/google_compute_known_hosts
</pre></div>


<p class="wp-block-paragraph">That is an expected behavior because the SSH tunnel is now established between your local machine and the VM.</p>



<h3 class="wp-block-heading" id="configuring-intellij-idea">Configuring IntelliJ IDEA</h3>



<p class="wp-block-paragraph">In IntelliJ IDEA, select <strong>Tools</strong> &gt; <strong>Deployment</strong> &gt; <strong>Browser Remote Host</strong></p>



<p class="wp-block-paragraph">Under <strong>Remote Host</strong> panel, select <strong>…</strong> button.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1.png?x45560"><img decoding="async" width="2362" height="492" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1.png?x45560" alt="" class="wp-image-1283" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1.png 2362w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1-300x62.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1-1024x213.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1-768x160.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1-1536x320.png 1536w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_41_31_pm-1-2048x427.png 2048w" sizes="(max-width: 2362px) 100vw, 2362px" /></a></figure>



<p class="wp-block-paragraph">Under <strong>Add Server</strong> dialog:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> <em>&lt;A Memorable Name&#8230; ex: shitty_server&gt;</em></li>



<li><strong>Type:</strong> SFTP</li>
</ul>



<p class="wp-block-paragraph">Click <strong>OK</strong> button.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1.png?x45560"><img decoding="async" src="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1.png?x45560" alt="" class="wp-image-1285" width="511" height="256" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1.png 1234w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1-300x150.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1-1024x513.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.42.48-pm-1-768x385.png 768w" sizes="(max-width: 511px) 100vw, 511px" /></a></figure>



<p class="wp-block-paragraph">Under <strong>Deployment</strong> dialog, select <strong>…</strong> button on <strong>SSH Configurations</strong>.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1.png?x45560"><img loading="lazy" decoding="async" width="1772" height="1268" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1.png?x45560" alt="" class="wp-image-1287" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1.png 1772w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1-300x215.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1-1024x733.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1-768x550.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_45_13_pm-1-1536x1099.png 1536w" sizes="auto, (max-width: 1772px) 100vw, 1772px" /></a></figure>



<p class="wp-block-paragraph">Under <strong>SSH Configurations</strong> dialog:</p>



<ul class="wp-block-list">
<li><strong>Host:</strong> localhost</li>



<li><strong>Port:</strong> 8888 <em>(or the local port you specified)</em></li>



<li><strong>User name:</strong> <em>&lt;Your VM&#8217;s user name&gt;</em></li>



<li><strong>Authentication type:</strong> Key pair</li>



<li><strong>Private key file:</strong> /<em>&lt;PATH&gt;</em>/.ssh/google_compute_engine</li>
</ul>



<p class="wp-block-paragraph">Click on <strong>Test Connection</strong> button and ensure it is successful.</p>



<p class="wp-block-paragraph">Click <strong>OK</strong> button.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1.png?x45560"><img loading="lazy" decoding="async" width="1956" height="1460" src="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1.png?x45560" alt="" class="wp-image-1289" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1.png 1956w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1-300x224.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1-1024x764.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1-768x573.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen-shot-2022-02-08-at-4.50.39-pm-1-1536x1147.png 1536w" sizes="auto, (max-width: 1956px) 100vw, 1956px" /></a></figure>



<p class="wp-block-paragraph">Under <strong>Deployment</strong> dialog, select <strong>Mappings</strong> tab.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1.png?x45560"><img loading="lazy" decoding="async" width="1772" height="1268" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1.png?x45560" alt="" class="wp-image-1291" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1.png 1772w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1-300x215.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1-1024x733.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1-768x550.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_02_pm-1-1536x1099.png 1536w" sizes="auto, (max-width: 1772px) 100vw, 1772px" /></a></figure>



<p class="wp-block-paragraph">Under <strong>Mapping</strong>s tab, click on the folder icon and specify a location to deploy the codebase to.</p>



<figure class="wp-block-image size-large is-resized"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1.png?x45560"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1.png?x45560" alt="" class="wp-image-1294" width="770" height="550" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1.png 1772w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1-300x215.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1-1024x733.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1-768x550.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_4_55_03_pm-2-1-1536x1099.png 1536w" sizes="auto, (max-width: 770px) 100vw, 770px" /></a></figure>



<p class="wp-block-paragraph">Click <strong>OK</strong> button.</p>



<p class="wp-block-paragraph">Under <strong>Remote Host</strong> panel, you can now browse and access the files in your VM remotely.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1.png?x45560"><img loading="lazy" decoding="async" width="2560" height="1945" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1.png?x45560" alt="" class="wp-image-1296" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1.png 2560w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1-300x228.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1-1024x778.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1-768x583.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1-1536x1167.png 1536w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_02_35_pm-1-2048x1556.png 2048w" sizes="auto, (max-width: 2560px) 100vw, 2560px" /></a></figure>



<h3 class="wp-block-heading" id="pushing-codebase-from-intellij-idea-to-vm">Pushing Codebase from IntelliJ IDEA to VM</h3>



<p class="wp-block-paragraph">To deploy codebase to the VM, right click on the directory, select <strong>Deployment</strong> &gt; <strong>Upload to [VM_NAME]</strong>.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1.png?x45560"><img loading="lazy" decoding="async" width="1530" height="1406" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1.png?x45560" alt="" class="wp-image-1298" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1.png 1530w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1-300x276.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1-1024x941.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_04_51_pm-1-768x706.png 768w" sizes="auto, (max-width: 1530px) 100vw, 1530px" /></a></figure>



<p class="wp-block-paragraph">The codebase should be copied to the location you specified.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1.png?x45560"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1.png?x45560" alt="" class="wp-image-1300" width="349" height="512" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1.png 770w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1-204x300.png 204w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1-697x1024.png 697w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_5_06_17_pm-1-768x1129.png 768w" sizes="auto, (max-width: 349px) 100vw, 349px" /></a></figure>



<p class="wp-block-paragraph">Tips: If you makes changes in both your local machine and VM, select <strong>Deployment</strong> &gt; <strong>Sync with Deployed to [VM_NAME]</strong>. This allows you to synchronize the changes on both sides.</p>



<h3 class="wp-block-heading" id="running-codebase-remotely">Running Codebase Remotely</h3>



<p class="wp-block-paragraph">To run the codebase remotely, select <strong>Tools</strong> &gt; <strong>Start SSH Session</strong>.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1.png?x45560"><img loading="lazy" decoding="async" width="1790" height="722" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1.png?x45560" alt="" class="wp-image-1311" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1.png 1790w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1-300x121.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1-1024x413.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1-768x310.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_22_pm-1-1536x620.png 1536w" sizes="auto, (max-width: 1790px) 100vw, 1790px" /></a></figure>



<p class="wp-block-paragraph">Select the configured host.</p>



<figure class="wp-block-image aligncenter size-large is-resized"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_38_pm.png?x45560"><img loading="lazy" decoding="async" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_19_38_pm.png?x45560" alt="" class="wp-image-1313" width="376" height="114"/></a></figure>



<p class="wp-block-paragraph">Run the codebase.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm.png?x45560"><img loading="lazy" decoding="async" width="2190" height="1712" src="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm.png?x45560" alt="" class="wp-image-1315" srcset="https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm.png 2190w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm-300x235.png 300w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm-1024x800.png 1024w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm-768x600.png 768w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm-1536x1201.png 1536w, https://myshittycode.com/wp-content/uploads/2022/02/screen_shot_2022-02-08_at_7_25_29_pm-2048x1601.png 2048w" sizes="auto, (max-width: 2190px) 100vw, 2190px" /></a></figure>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2022/02/08/gcp-pushing-codebase-from-intellij-idea-to-vm-instance/">GCP: Pushing Codebase from IntelliJ IDEA to VM Instance</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2022/02/08/gcp-pushing-codebase-from-intellij-idea-to-vm-instance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1267</post-id>	</item>
		<item>
		<title>Ansible: Handling Multiple Hosts via SSH</title>
		<link>https://myshittycode.com/2021/05/19/ansible-handling-multiple-hosts-via-ssh/</link>
					<comments>https://myshittycode.com/2021/05/19/ansible-handling-multiple-hosts-via-ssh/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 19 May 2021 13:28:47 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Ansible]]></category>
		<category><![CDATA[MacOS]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1217</guid>

					<description><![CDATA[<p>PROBLEM To run Ansible playbook in multiple hosts via SSH. SOLUTION Configuring SSH environment Ensure SSH keypair exists on the current machine (ex: ~/.ssh/id_rsa for private key and ~/.ssh/id_rsa.pub for public key). If you do not have one, create one: Copy the public key (ex: ~/.ssh/id_rsa.pub) to each remote host&#8217;s ~/.ssh/authorized_keys. If this file doesn&#8217;t [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2021/05/19/ansible-handling-multiple-hosts-via-ssh/">Ansible: Handling Multiple Hosts via SSH</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">PROBLEM</h2>



<p class="wp-block-paragraph">To run Ansible playbook in multiple hosts via SSH.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<h3 class="wp-block-heading">Configuring SSH environment</h3>



<p class="wp-block-paragraph">Ensure SSH keypair exists on the current machine (ex: <strong>~/.ssh/id_rsa</strong> for private key and <strong>~/.ssh/id_rsa.pub</strong> for public key). If you do not have one, create one:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ssh-keygen
</pre></div>


<p class="wp-block-paragraph">Copy the public key (ex: <strong>~/.ssh/id_rsa.pub</strong>) to each remote host&#8217;s <strong>~/.ssh/authorized_keys</strong>. If this file doesn&#8217;t exist, create it.</p>



<p class="wp-block-paragraph">Ensure the current machine&#8217;s <strong>.ssh/</strong> directory and file have correct permission.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
</pre></div>


<p class="wp-block-paragraph">In the current machine&#8217;s <strong>/etc/hosts</strong>, add all remote hosts.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
127.0.0.1      localhost  # current machine
192.168.1.100  donkeykong # remote host 1
192.168.1.200  supermario # remote host 2
</pre></div>


<p class="wp-block-paragraph">In each remote host, enable the remote login and grant yourself the access to this service.</p>



<figure class="wp-block-image size-large"><a href="https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1.png?x45560"><img loading="lazy" decoding="async" width="1200" height="988" src="https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1.png?x45560" alt="" class="wp-image-1226" srcset="https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1.png 1200w, https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1-300x247.png 300w, https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1-1024x843.png 1024w, https://myshittycode.com/wp-content/uploads/2021/05/remote-login-1-768x632.png 768w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></a><figcaption class="wp-element-caption">Enabling Remote Login on Mac</figcaption></figure>



<p class="wp-block-paragraph">Test SSH connection to remote host to ensure they work first before working on Ansible playbook.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ssh user@donkeykong
ssh user@supermario
</pre></div>


<h3 class="wp-block-heading">Creating Ansible Playbook</h3>



<p class="wp-block-paragraph">Create <strong>ansible.cfg</strong> and define the location of inventory file.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&#x5B;defaults]
inventory = inventory.yml
</pre></div>


<p class="wp-block-paragraph">Create <strong>inventory.yml</strong> and define both localhost and remote hosts.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
all:
  hosts:
    localhost:
      ansible_connection: local
    donkeykong:
      ansible_user: user
      ansible_ssh_private_key_file: ~/.ssh/id_rsa
    supermario:
      ansible_user: user
      ansible_ssh_private_key_file: ~/.ssh/id_rsa
</pre></div>


<p class="wp-block-paragraph">Run a test to ensure the connection to remote hosts are successful.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ansible all -i inventory.yml -m ping
</pre></div>


<p class="wp-block-paragraph">If successful, the output looks something like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
localhost | SUCCESS =&gt; {
    &quot;changed&quot;: false,
    &quot;ping&quot;: &quot;pong&quot;
}
donkeykong | SUCCESS =&gt; {
    &quot;changed&quot;: false,
    &quot;ping&quot;: &quot;pong&quot;
}
supermario | SUCCESS =&gt; {
    &quot;changed&quot;: false,
    &quot;ping&quot;: &quot;pong&quot;
}
</pre></div>


<p class="wp-block-paragraph">Create <strong>main.yml</strong> with a very simple task.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
- name: all-hosts
  hosts: all
  tasks:
    - name: Capture current dir
      shell: pwd
      register: output

    - name: Display output
      debug: msg=&#039;{{ output.stdout }}&#039;
</pre></div>


<p class="wp-block-paragraph">Run the playbook.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ansible-playbook main.yml
</pre></div>


<p class="wp-block-paragraph">If successful, the output looks something like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
PLAY &#x5B;all-hosts] *******************************************************************************************************

TASK &#x5B;Gathering Facts] *************************************************************************************************
ok: &#x5B;localhost]
ok: &#x5B;donkeykong]
ok: &#x5B;supermario]

TASK &#x5B;Capture current dir] *********************************************************************************************
changed: &#x5B;localhost]
changed: &#x5B;donkeykong]
changed: &#x5B;supermario]

TASK &#x5B;Display output] **************************************************************************************************
ok: &#x5B;localhost] =&gt; {
    &quot;msg&quot;: &quot;/Users/user/myshittycode&quot;
}
ok: &#x5B;donkeykong] =&gt; {
    &quot;msg&quot;: &quot;/Users/user&quot;
}
ok: &#x5B;supermario] =&gt; {
    &quot;msg&quot;: &quot;/Users/user&quot;
}

PLAY RECAP *************************************************************************************************************
donkeykong                 : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
supermario                 : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
</pre></div>


<h3 class="wp-block-heading">Controlling the Hosts</h3>



<p class="wp-block-paragraph">Sometimes, you want finer controls on what tasks to be ran in certain hosts.</p>



<p class="wp-block-paragraph">To run in just one host (ex: <strong>donkeykong</strong>):</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; highlight: [2]; title: ; notranslate">
- name: one-host
  hosts: donkeykong
  tasks:
    - ...
</pre></div>


<p class="wp-block-paragraph">To run in all remote hosts except localhost:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; highlight: [2]; title: ; notranslate">
- name: all-hosts-except-localhost
  hosts: all:!localhost
  tasks:
    - ...
</pre></div>


<p class="wp-block-paragraph"></p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2021/05/19/ansible-handling-multiple-hosts-via-ssh/">Ansible: Handling Multiple Hosts via SSH</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2021/05/19/ansible-handling-multiple-hosts-via-ssh/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1217</post-id>	</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 
Lazy Loading (feed)
Database Caching 60/77 queries in 0.039 seconds using Disk

Served from: myshittycode.com @ 2026-07-07 01:26:13 by W3 Total Cache
-->