Jul
26
TTT Part 39 of n – Advanced TMUX
Filed Under System Administration, Computers & Tech on July 26, 2020 | Leave a Comment
In the previous instalment we learned how to use the tmux
as a replacement for the screen
command which has been deprecated on RedHat Enterprise Linux (and hence CentOS too). In this instalment we’ll take TMUX to the next level, making use of the fact that a single TMUX session can contain arbitrarily many windows, each consisting of arbitrarily many panes.
As a reminder from last time — in the TMUX-universe, sessions contain windows contain panes. By default a session contains one window which contains one full-width and full-height pane. Windows can be thought of as stacking behind each other, like tabs in a browser, and panes are arrayed next to each other within a window.
Feb
26
Generating SSH Keys on Windows with PuTTYgen
Filed Under System Administration, Security, Computers & Tech on February 26, 2020 | 1 Comment
In instalment 30 of the Taming the Terminal series I showed how SSH keys can be used to more securely and conveniently connect to servers. The instructions in that instalment are for Linux-like OSes (including MacOS) where the standard OpenSSH tools are available.
Windows doesn’t ship with OpenSSH (or indeed any SSH implementation), so Windows users who want to SSH need to install some kind of additional software. With Windows 10 there is the obvious option of installing the Windows Subsystem for Linux, but people may prefer a GUI experience. The obvious choice for Windows users is the venerable free and open source PuTTY suite of tools.
The PuTTY SSH client itself is easy to use, and if you install the full suite of apps via the MSI installer (available on their download page) you’ll also get a GUI for generating SSH keys named PuTTYgen.
Jun
17
Moving my .bashrc to .zshrc
Filed Under System Administration, Computers & Tech on June 17, 2019 | 1 Comment
Having used Zsh rather than Bash for over a week it was time to make the move permanent by migrating my shell customisations from ~/.bashrc
to ~/.zshrc
. Your milage may vary, but I was pleased to find I didn’t need to make any changes, and, that I could get rid of one command from the script because Zsh defaults to a behaviour I had to explicitly opt in to with Bash.
TL;DR: environment variables (including PATH
) and aliases work just the same in Zsh as they do in Bash, so if those are the only things you alter in your ~/.bashrc
, then you can just copy it over to ~/.zshrc
. But, if you alter Bash settings in your ~/.bashrc
, you’ll need figure out the equivalent Zsh options and replace the relevant lines with the appropriate Zsh setopt
or unsetopt
Zsh commands.
Jun
17
Moving from Bash to Zsh on macOS
Filed Under System Administration, Computers & Tech on | Leave a Comment
During their 2019 World Wide Developers Conference (WWDC 2019) Apple announced that the default command shell for their next OS release (macOS Catalina) from the Bourne Again Shell (Bash) to the Z Shell (Zsh). Not only will Apple be switching the default in Catalina, they will be removing Bash completely in an as-yet unspecified future update. Apple’s advice is clear — make the switch now so you’re ready!
Never being one to try hold back the tide, I dove right in and made the switch within 5 minutes of reading about the announcement. This series will document my experience of making the change.
Jun
13
Bash to Zsh: Allowing Comments in Interactive Shells
Filed Under System Administration, Computers & Tech on June 13, 2019 | Leave a Comment
As I continue my move from Bash to Zsh at Apple’s strong suggestion I continue to bump into little differences that cause me minor problems. Today it was the fact that while Bash treats comments as comments even when they’re entered in an interactive shell, Zsh does not, at least not by default on MacOS.
TL;DR – setopt INTERACTIVE_COMMENTS
Jun
12
Getting Back to Bash from Zsh on MacOS
Filed Under System Administration, Computers & Tech on June 12, 2019 | Leave a Comment
At Apple’s advice I’ve switched the login shell from Bash to Zsh on all my Macs. For the most part, what worked in Bash works in Zsh, but sometimes I do still want to get back to Bash to test something or to check something. You might imagine that simply typing bash
from a Zsh prompt would get you a Bash shell, and you’d be right, sort of. When you just run the command bash
you get a bare shell without the customisations that would have been applied when you opened a new Terminal window with Bash as your default shell. This will be immediately obvious because the prompt will be the basic bash-3.2$
as opposed to the hostname, current folder, and you’re username like you were used to.
The solution is really simple — pass the -l
flag to signify that you want your new shell treated like a login shell, and hey presto, you’re back to Bash just like you remembered it 🙂
So, if you switch your Mac to Zsh, you get back to the Bash experience you had before with the following command:
bash -l
Jun
12
Bash to Zsh: File Globbing and ‘no matches found’ Errors
Filed Under System Administration, Computers & Tech on | Leave a Comment
At Apple’s recommendation I’ve moved from Bash to Zsh on all my Macs. This has been a mostly smooth transition, but I have run into a handful of little gotchas. This week it was an error when trying to execute a command I’d been using in Bash for years. The error started zsh: no matches found
.
The cause of this error is a subtle but important difference in how Bash and Zsh handle file globbing (expansion of the *
character) when no files match the specified pattern. By default, Bash happily expands expressions that don’t match anything into an empty list. Zsh’s default behaviour is to raise an error and prevent the command executing.
TL;DR — setopt NULL_GLOB
to enable Bash-like behaviour, and unsetopt NULL_GLOB
to revert back to the Zsh-like behaviour.
Jun
6
Getting a Bash-like Prompt in Zsh
Filed Under System Administration, Computers & Tech on June 6, 2019 | Leave a Comment
Apple recently announced that it’s moving the MacOS from the Bourne-again Shell (Bash) to the Z Shell (Zsh), and advised developers to make the change now, so they’re ready when they remove Bash altogether in some later version of the OS. Since I’m a big believer in not swimming up-stream, I decided to take their advice and switched to the Z Shell immediately.
The first thing I noticed was that the default prompt Apple provides for Zsh on their OS gives a lot less information than their default for Bash did. This is a sample of their old Bash prompt:
bart-imac2018:Documents bart$
That tells me the machine I’m on (bart-imac2018
), the folder I’m in (Documents
), and the username the shell is running as (bart
), and whether or not I have super-user privileges ($
means no, #
means yes). These are all very useful things, particularly when you SSH around a lot and su
/sudo
to different accounts. Also, IMO showing only the top-level folder rather than the full path gives a nice balance between the prompt getting too big, and not knowing where you are. I’ve never felt an urge to change the Mac’s default Bash prompt.
I can’t say the same about the Mac’s default Z Shell prompt! This is what I get on the same machine with the Z shell:
bart-imac2018%
It only shows the machine name (bart-imac2018
) and whether or not I have super-user privileges (%
for no, #
for yes)!
Thankfully getting back to the old Bash-like prompt is easy — the TL;DR version is that you simply need to add the following line to your ~/.zshrc
file:
PROMPT='%m:%1~ %n%# '
If you’d like to understand how exactly that works, and what other choices you have, read on!
May
25
TTT Part 37 of n – SSH Agents
Filed Under System Administration, Computers & Tech on May 25, 2017 | 2 Comments
Since we covered SSH in parts 29 & 30, Apple have changed how their desktop OS deals with the passphrases protecting SSH identities (key pairs). This provides us a good opportunity to have a look at the SSH Agent in general, and, how things have changed on the Mac in particular.
The good news is that while things have changed on the Mac, with a small amount of effort, you can get back all the convenience and security you had before.
Nov
19
TTT Part 36 of n – screen & cron
Filed Under System Administration, Computers & Tech on November 19, 2016 | 4 Comments
The previous 13 instalments in this series related to networking, but we’re going to change tack completely for this instalment, and look at two un-reltaed, but very useful terminal commands – screen
, and cron
.
screen
is a utility that allows for the creation of persistent virtual terminal sessions that you can disconnect from without terminating, and reconnect and pick up where you left off at a later time. screen
is particularly useful when used in conjunction with SSH.
cron
on the other hand is a system for automatically executing recurring tasks. It’s extremely flexible, and very useful for things like scheduling backups to run in the middle of the night.