<?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>DEV Community: Wardterm</title>
    <description>The latest articles on DEV Community by Wardterm (@wardterm).</description>
    <link>https://dev.to/wardterm</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4246039%2Fe74d6941-a47a-412e-8fab-4cf658264bbe.png</url>
      <title>DEV Community: Wardterm</title>
      <link>https://dev.to/wardterm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wardterm"/>
    <language>en</language>
    <item>
      <title>How to use Mosh on Mac and iPhone, and keep sessions alive with tmux</title>
      <dc:creator>Wardterm</dc:creator>
      <pubDate>Sun, 15 Nov 2026 14:12:26 +0000</pubDate>
      <link>https://dev.to/wardterm/how-to-use-mosh-on-mac-and-iphone-and-keep-sessions-alive-with-tmux-58lc</link>
      <guid>https://dev.to/wardterm/how-to-use-mosh-on-mac-and-iphone-and-keep-sessions-alive-with-tmux-58lc</guid>
      <description>&lt;p&gt;SSH drops the moment your laptop sleeps, your train goes into a tunnel or your iPhone switches from Wi-Fi to 5G. Mosh fixes the connection part. tmux fixes the "my job died with it" part. Together they make a remote shell you can close and reopen from anywhere.&lt;/p&gt;

&lt;p&gt;This guide sets up both on a Linux server and shows how to connect from a Mac and from an iPhone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# on the server&lt;/span&gt;
sudo apt install mosh tmux          &lt;span class="c"&gt;# Debian / Ubuntu&lt;/span&gt;
sudo ufw allow 60000:61000/udp      &lt;span class="c"&gt;# only if ufw is on&lt;/span&gt;

&lt;span class="c"&gt;# on the Mac&lt;/span&gt;
brew install mosh
mosh user@your-server -- tmux new -A -s main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;tmux new -A -s main&lt;/code&gt; attaches to the session called &lt;code&gt;main&lt;/code&gt; if it exists, or creates it. Run the same command again tomorrow and you are back where you left off.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Mosh does, and what it does not
&lt;/h2&gt;

&lt;p&gt;Mosh (mobile shell) logs in over SSH, starts &lt;code&gt;mosh-server&lt;/code&gt; on the remote machine, and then talks to it over UDP. Because the session is not tied to one TCP connection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it survives a change of IP address (Wi-Fi to cellular, home to office);&lt;/li&gt;
&lt;li&gt;it survives the laptop sleeping or the iPhone locking;&lt;/li&gt;
&lt;li&gt;it shows what you type right away, even on a slow link, instead of waiting for the server's echo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it does not do: keep your programs running if the server side of the session ends, scroll back through history the way your terminal does, or forward ports. For the first two, you add tmux.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install on the server
&lt;/h2&gt;

&lt;p&gt;Debian and Ubuntu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt update
sudo apt install mosh tmux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fedora, RHEL and friends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo dnf install mosh tmux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mosh uses one UDP port per session in the range 60000 to 61000. If a firewall is on, open it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo ufw allow 60000:61000/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a cloud server, add the same range as an inbound UDP rule in the provider's firewall too.&lt;/p&gt;

&lt;p&gt;Mosh also needs a UTF-8 locale on the server. If you get an error about &lt;code&gt;LANG&lt;/code&gt; or &lt;code&gt;LC_ALL&lt;/code&gt;, this usually fixes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo locale-gen en_US.UTF-8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Connect from a Mac
&lt;/h2&gt;

&lt;p&gt;Install the client with Homebrew and connect the same way you would with SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew install mosh
mosh user@your-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If SSH runs on another port, pass the SSH command through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mosh --ssh=&lt;span class="s2"&gt;"ssh -p 2222"&lt;/span&gt; user@your-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your &lt;code&gt;~/.ssh/config&lt;/code&gt; is used as usual, so a host alias works too: &lt;code&gt;mosh myserver&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add tmux so the work survives
&lt;/h2&gt;

&lt;p&gt;Mosh keeps the connection alive. tmux keeps the programs alive, even if you close the Mosh session on purpose or the server reboots your login.&lt;/p&gt;

&lt;p&gt;Start or reattach in one step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mosh myserver -- tmux new -A -s main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The keys you need on day one:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Keys&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Ctrl-b d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;detach: leave everything running and disconnect&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Ctrl-b c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;new window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;Ctrl-b n&lt;/code&gt; / &lt;code&gt;Ctrl-b p&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;next / previous window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Ctrl-b %&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;split side by side&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Ctrl-b [&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;scroll back (press &lt;code&gt;q&lt;/code&gt; to leave)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Later, from any device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tmux ls                  &lt;span class="c"&gt;# list sessions&lt;/span&gt;
tmux attach -t main      &lt;span class="c"&gt;# go back in&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the setup many people use to leave a long build, a database migration or an AI coding agent such as Claude Code or Codex running on a server and check on it from the phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect from an iPhone or iPad
&lt;/h2&gt;

&lt;p&gt;iOS has no built-in terminal, so you need an SSH app that supports Mosh. Look for three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Mosh support&lt;/strong&gt;, not only SSH, so the session survives the phone locking;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;key handling&lt;/strong&gt; you trust, ideally keys that never leave the device;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a way to reattach&lt;/strong&gt; to your tmux session without typing the command every time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The flow is the same as on the Mac: connect with Mosh, then &lt;code&gt;tmux new -A -s main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We make Wardterm, an SSH client for Mac, iPhone and iPad, and we built it around this exact workflow. Mosh is included on every device, and Keep This Session moves the current session into tmux on the server for you, so you can close the app and pick it up later from the Mac or the phone. If you run AI agents on the server, it also tells you when one is waiting for an answer. The free plan has no limit on servers: &lt;a href="https://wardterm.com/" rel="noopener noreferrer"&gt;https://wardterm.com/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;"mosh-server: command not found"&lt;/strong&gt;&lt;br&gt;
Mosh is not installed on the server, or not on the &lt;code&gt;PATH&lt;/code&gt; of a non-interactive SSH login. Install it, or point to it: &lt;code&gt;mosh --server=/usr/local/bin/mosh-server user@host&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It hangs at "Connecting..." and then times out&lt;/strong&gt;&lt;br&gt;
UDP is blocked. Open 60000-61000/udp on the server firewall and on the cloud provider's firewall. Corporate and hotel networks often block UDP: SSH plus tmux still works there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"The locale requested by LC_ALL=... isn't available"&lt;/strong&gt;&lt;br&gt;
Generate a UTF-8 locale on the server (&lt;code&gt;sudo locale-gen en_US.UTF-8&lt;/code&gt;) or set &lt;code&gt;LANG=en_US.UTF-8&lt;/code&gt; on the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scrolling with the trackpad does nothing&lt;/strong&gt;&lt;br&gt;
Mosh does not keep scrollback. Use tmux: &lt;code&gt;Ctrl-b [&lt;/code&gt;, then arrow keys or Page Up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mosh keeps the connection alive across network changes and sleep.&lt;/li&gt;
&lt;li&gt;tmux keeps your programs alive and lets you reattach from any device.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mosh myserver -- tmux new -A -s main&lt;/code&gt; is the one command to remember.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A longer comparison of Mosh clients for Mac and iPhone is on our blog: &lt;a href="https://wardterm.com/blog/best-mosh-client/" rel="noopener noreferrer"&gt;https://wardterm.com/blog/best-mosh-client/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>mosh</category>
      <category>tmux</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
