Did you know that you can run a Linux command line on an iOS device? You might be asking, “Why should I use text apps on iPhone?” Fair question. But if you're reading Opensource.com, you probably know the answer: Linux users want to be able to use it on any device and want to use their own settings.
But most of all they crave solving complex problems.
I have a seven year old iPad 2 Mini which is still good for ebook reading and other tasks. However, I also want to use it to access the command line of applications with my set of programs and scripts, without which I cannot work. I need an environment that I'm used to, as well as my standard development environment. And here is how I managed to achieve this.
Connecting to a keyboard
Working with the command line for programming through the on-screen keyboard of a phone or tablet is quite inconvenient. I recommend connecting an external keyboard, either via Bluetooth or using a camera connection adapter to connect a wired keyboard (I chose the latter). Connecting a Kinesis Advantage split keyboard to an iPhone 6 results in a weird device that looks like
Installing the shell on iOS
To run a fully functional Linux system on iOS, there are two options:
- Secure shell (SSH) connected to a Linux machine
- Running a virtual system using Alpine Linux with iSH, which is open source but must be installed using Apple's proprietary TestFlight application
Alternatively, there are two open source terminal emulator applications that provide the ability to work with open-source tools in a limited environment. This is the most stripped-down option - in fact, this is not how you run Linux, but Linux tools. There are severe limitations when working with these applications, but you get partial command line functionality.
Before moving on to complex solutions, I will consider the simplest way.
Option 1: Shell in the Sandbox
One of the easiest ways is to install the iOS app
Approximately the same functionality
Option 2: SSH
Another step beyond downloading an app is setting up an SSH client. For a long time, we have been able to use any of the many iOS SSH client applications to connect to a server running Linux or BSD. The advantage of using SSH is that any distribution can run on the server with any software. You work remotely and the results of your work are simply transferred to the terminal emulator on your iOS device.
Option 3: Run Linux
Using SSH to connect to a server under Linux is a great way to access the command line, but it requires an external server and a network connection. This is not the biggest obstacle, but it cannot be completely ignored, so you may need to work with Linux without a server.
If this is your case, then you will need to take it one step further.
Running Alpine Linux with iSH
Important feature: application experimental. Since iSH is currently a test application, don't expect consistent and reliable performance. TestFlight applications are time limited. My current build will only run 60 days. This means that after 60 days I will be expelled and will have to rejoin the next phase of iSH testing. Moreover, I will lose all my files if I don't export them with Files on iOS or copy them to a Git host or
iSH Installation
Start with installation
Using the link, TestFlight will install the iSH app on your device. As with any other application, an icon will appear on the screen.
Package management
iSH runs an x86 emulator with Alpine Linux. Alpine is a tiny distribution that is less than 5MB in size. This was my first time working with Alpine, so I thought the minimalism would be annoying, but I really liked it.
Alpine uses a package manager
How to install the package:
apk add package
How to remove a package:
apk del package
How to find out other commands and information:
apk --help
Package manager update:
apk update
apk upgrade
Installing a text editor
Alpine's default text editor is Vi, but I prefer Vim, so I installed it:
apk add vim
Optionally, you can install Nano or Emacs.
Shell change
I don't know about you, but I needed
fish installation:
apk add fish
If you need Bash with its autocompletion and man pages, then install them:
apk add bash bash-doc bash-completion
Alpine's minimalist ideology usually means that some programs that are a single package on other distributions will be split into several smaller packages. It also means that you can tune and downsize the system just the way you want it.
For more information on installing Bash, see
Changing the default shell
Once fish is installed, you can temporarily switch to it by typing fish
and going to the shell. But I want to make fish the default shell, and the command chsh
, which I used in other distributions, did not work.
First, let's find out where fish is installed:
which fish
Here's what happened to me:
/usr/bin/fish
Next, change the login shell to fish. You can use any editor you like. If you are a beginner, then install Nano (with the command apk add nano
) so that you can edit the configuration files and save them via CTRL+X, confirm and exit.
But I used Vim:
vim /etc/passwd
My first line was:
root:x:0:0:root:/root:/bin/ash
To make fish the default shell, change this line to the following:
root:x:0:0:root:/root:/usr/bin/fish
Then save the file and exit.
I'm sure there is a good way to change the shell path so that it can be used right away. But I don’t know him, so I recommend returning to the application browser, force exiting the shell, and to be sure, turn off and restart the iPad or iPhone. Open iSH again and now, in addition to the message “Welcome to Alpine!” and information about launching from the apk, you will see the standard fish login welcome message: Welcome to fish, the friendly interactive shell... Hooray!
Setting up Python and pip
I decided to add
apk add python3
Although Python 2.x is outdated, you can install it too:
apk add python
Install a Python package manager called pip and
python3 -m ensurepip --default-pip
It will take some time to install and configure the package manager, so just be patient.
You can then download a tool to transfer files over the network
apk add curl
Reading manuals
Fish uses built-in autocompletion based on man pages. Like other command line users, I use the manual man
, and Alpine does not have it installed. So I installed it with a terminal pager
apk add man man-pages less less-doc
In addition to man, I use the magnificent
I installed it with pip:
pip install tldr
Team tldr
connects to the web to fetch pages when it encounters a request for a new page. If you need to know how to use a command, you can write something like tldr curl
and get a description in plain English and good examples on how to use the command.
Of course, all this installation work can be automated using
Additional Information
The iSH Wiki has a page "
Another wiki page explains how
You can also install Git (yes! apk add git
) and push your work to a remote repository or push it to the server via SSH. And, of course, you can download and run any number of great open-source projects from GitHub.
More information about iSH can be found at these links:
As advertising
Vdsina offers
Source: habr.com