<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Joseph Midura</title>
    <description>The latest articles on Forem by Joseph Midura (@josephmidura).</description>
    <link>https://forem.com/josephmidura</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F584460%2F001cc984-9752-4253-a140-0513e8ad7645.jpg</url>
      <title>Forem: Joseph Midura</title>
      <link>https://forem.com/josephmidura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/josephmidura"/>
    <language>en</language>
    <item>
      <title>Update Homebrew on macOS With One Script</title>
      <dc:creator>Joseph Midura</dc:creator>
      <pubDate>Wed, 14 Jul 2021 14:41:50 +0000</pubDate>
      <link>https://forem.com/josephmidura/update-homebrew-on-macos-with-one-script-2lk0</link>
      <guid>https://forem.com/josephmidura/update-homebrew-on-macos-with-one-script-2lk0</guid>
      <description>&lt;p&gt;I use multiple Homebrew packages and I appreciate Homebrew's built in package management, so each time I update Homebrew packages on my mac, I get tired of typing multiple commands, especially since I like to be thorough. I use &lt;code&gt;brew update&lt;/code&gt; to update the formula and Homebrew itself, &lt;code&gt;brew upgrade&lt;/code&gt; to update everything, &lt;code&gt;brew cleanup&lt;/code&gt; to delete any unfinished downloads, and finally &lt;code&gt;brew doctor&lt;/code&gt; to check for issues. &lt;/p&gt;

&lt;p&gt;My initial thought was that I could just create a simple alias to run all four commands at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;brewup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'brew update; brew upgrade; brew cleanup; brew doctor'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I decided to improve on the idea and create a bash script that would run all the commands and echo messages back to me as it was running. I did it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;CYAN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;tput setaf 6&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;RESET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;tput sgr0&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CYAN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;Updating homebrew and local base of available packages and versions...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;RESET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
brew update

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CYAN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;Upgrading outdated homebrew packages...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;RESET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
brew upgrade

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CYAN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;Cleaning cache of unfinished downloads...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;RESET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
brew cleanup

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;CYAN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;Checking for issues...&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;RESET&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
brew doctor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the echo command to tell me which part of the script is currently being executed, so if the script appears to be hanging I know how far it completed. I formatted the text to use a color that doesn’t appear elsewhere in my terminal's color scheme so that I know that the outputted text is from my script rather than as a result of a Homebrew process.&lt;/p&gt;

&lt;p&gt;Finally, I named the script brewup, stuck it in my ~/bin directory and made it executable from any directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x brewup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the script is executable I can run the script no matter how far down I'm working in a nested directory. When I want to update my Homebrew packages, I can type a single word and let Homebrew update in one terminal window while I work on something else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brewup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This post also appeared on my &lt;a href="https://josephmidura.wordpress.com/2021/07/03/updating-homebrew-on-macos/?preview_id=108&amp;amp;preview_nonce=6552e242a6&amp;amp;preview=true" rel="noopener noreferrer"&gt;blog&lt;/a&gt;. If you like what I did and want to save yourself some typing, you can get a copy of the script from my &lt;a href="https://gist.github.com/josephmidura/807770766aeb37b9cc3897e26f870210" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Comments and suggestions are welcome.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>scripting</category>
      <category>productivity</category>
      <category>homebrew</category>
    </item>
    <item>
      <title>How to Manage Multiple SSH Key Pairs</title>
      <dc:creator>Joseph Midura</dc:creator>
      <pubDate>Sun, 18 Apr 2021 20:49:28 +0000</pubDate>
      <link>https://forem.com/josephmidura/how-to-manage-multiple-ssh-key-pairs-1ik</link>
      <guid>https://forem.com/josephmidura/how-to-manage-multiple-ssh-key-pairs-1ik</guid>
      <description>&lt;p&gt;Most developers will interact with resources that use SSH keys instead of passwords. I recently overheard someone say that he uses the same SSH key for all of his accounts, which is a bad idea from a security perspective. The more places a single key is authorized, the more valuable that key becomes. If that key gets compromised, more targets are put at risk. There are other reasons I might have multiple key pairs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Team resources that share the same key&lt;/li&gt;
&lt;li&gt;Older systems that don't support the newest ed25519 encryption algorithm&lt;/li&gt;
&lt;li&gt;Separate keys for each consulting client I have&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When I initially started managing multiple SSH key/password combinations on my personal machine, I learned best practices from a variety of sources. I’m writing this information down in one place for the benefit of others. My current OS of choice is MacOS, but these instructions should work for any *nix system. Atlassian &lt;a href="https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/" rel="noopener noreferrer"&gt;recommends&lt;/a&gt; users replace their SSH keys once a year for security. Following these steps will ensure that you can. &lt;/p&gt;

&lt;h2&gt;
  
  
  First: Generate a new key
&lt;/h2&gt;

&lt;p&gt;Open terminal and navigate to ~/.ssh to generate a new SSH key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; ed25519 &lt;span class="nt"&gt;-f&lt;/span&gt; ~/.ssh/key_name &lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="s2"&gt;"name@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what each flag means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-t specifies the algorithm that makes the key. &lt;/li&gt;
&lt;li&gt;-f specifies a custom name for the key (assuming you're in the ~/.ssh directory), and an alternate location if it’s in the form of a path. The key_name is the name of the key. Make this as specific as possible.&lt;/li&gt;
&lt;li&gt;-C is an option to include a comment. It can be anything but is usually in the form user@host (who generated the key)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I always use a key name that is specific and makes sense to me. This makes key management easier in the long term. You should use a passphrase when prompted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Second: Create known_hosts file
&lt;/h2&gt;

&lt;p&gt;When you complete the first step two files are created: key_name and key_name.pub. The first is your private key and the second (with the .pub extension) is your public key. &lt;/p&gt;

&lt;p&gt;Create a known_hosts file for each account you have because it makes diagnosing issues easier when you have multiple keys. Ideally the name of this file is similar enough to the key name that you aren’t confused later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;known_hosts_keyname 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Third: Set up the config file
&lt;/h2&gt;

&lt;p&gt;The config file sets options for each host. Create the config file if it doesn’t already exist and then open it for editing. I label each key for visual neatness and to avoid confusion as the list of keys gets longer over time. Create a comment using the # at the start of a line to label each host. The text in the picture below is available &lt;a href="https://gist.github.com/josephmidura/407b59d34e45a76622dc86909dd69bd8" rel="noopener noreferrer"&gt;here&lt;/a&gt; to save you some typing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkztx48m2m559lzk85zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkztx48m2m559lzk85zt.png" alt="config" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the breakdown of what each line means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Host&lt;/strong&gt; is a pattern matcher that is used to differentiate between these sets of configurations. Keep it the same as the HostName so it matches hosts in connections correctly without additional specification. &lt;/li&gt;
&lt;li&gt;The URL on the &lt;strong&gt;HostName&lt;/strong&gt; line is the base URL where the repository resides. For example, if you have a personal account on github with personal projects, the URL will be github.com. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User&lt;/strong&gt; for git based systems will be git. The value of User will be different if you connect to something else (i.e.  ec2-user for connecting to an Amazon AWS EC2 instance)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IdentityFile&lt;/strong&gt; asks for the location of the identity key we made. Type in the respective path here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AddKeysToAgent&lt;/strong&gt; allows a private key that is used during authentication to be added to ssh-agent if it is running&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UseKeychain&lt;/strong&gt; (macOS only) allows the computer to remember the password each time it restarts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UserKnownHostsFile&lt;/strong&gt; specifies an exact location to store all hosts you connect to when you’re using that profile. Provide the respective paths here and choose a unique known hosts file name (see step 2 above) so that troubleshooting and key maintenance over time is easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IdentitiesOnly&lt;/strong&gt; specifies that only the keys provided must be used to connect to a host, even if another service like the ssh-agent offers a key for use.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fourth: Add keys to ssh agent
&lt;/h2&gt;

&lt;p&gt;Add keys to ssh agent if passphrase was used. Skip to the next step if you didn't use a passphrase. Start the ssh agent in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;ssh-agent &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;strong&gt;private&lt;/strong&gt; keys to the agent in terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-add &lt;span class="nt"&gt;--apple-use-keychain&lt;/span&gt; ~/.ssh/key_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the --apple-use-keychain option works only on Mac for keychain access. (In versions of MacOS prior to Monterey, use -K rather than --apple-use-keychain).&lt;/p&gt;

&lt;h2&gt;
  
  
  Fifth: Finishing up
&lt;/h2&gt;

&lt;p&gt;If you're using a service like Bitbucket or Github, add &lt;strong&gt;public&lt;/strong&gt; keys to the clipboard and paste them into the appropriate account (i.e. Bitbucket):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;key_name.pub | pbcopy 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, verify the configuration in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-T&lt;/span&gt; git@bitbucket.org 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With multiple keys, I have the option of creating new keys as needed to keep each connection secure. If I have a single compromised key, then I only worry about changing that single key. My config file makes it easy for me to use multiple keys.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;br&gt;
&lt;a href="http://www.openssh.com" rel="noopener noreferrer"&gt;OpenSSH documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/" rel="noopener noreferrer"&gt;Bitbucket documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh" rel="noopener noreferrer"&gt;Github documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>ssh</category>
      <category>security</category>
    </item>
  </channel>
</rss>
