iOS Pythonista 3: Using SSH

Use SSH in Pythonista 3 (StaSh)

SSH in StaSh seems not to work if a passphrase is given to create keys. I found some hosting servers do not accept passphrase (password) to connect using SSH. In this post you can find a way to careate SSH keys in Pythonista 3 (SSH command in StaSh) with no passphrase.

Generate SSH keys in StaSh

$ ssh-keygen -t rsa -b 2048

Secret key and Public key are generated in the following path.

~/Documents/site-packages/stash/.ssh
$ ls
id_rsa id_rsa.pub

Copy the public key “id_rsa.pub” to your SSH server’s appropriate location.

SSH command to connect to your server

$ ssh username@username.xsrv.jp -p 10022

Above is an example to connect to XServer hosting server that I use. Change username, host name (“username.xsrv.jp” in this example) and port number (10022 in this case).

When you first run the ssh command in Pythonista 3, a terminal emulator “pyte” will be installed automatically. In this case you’ll see global name 'pyte' is not defined error message and need to quit and relaunch Pythonista 3.

Additional Notes – Set number of lines

Once the above is complete, you will want to add an alias (shortcut command) to the .stashrc file (Reference), copy the SSH keys to another SSH app, iOS device or computer. Make sure that you do not share “ids_rsa” the secret key file with anyone. Create .ssh folder in the same path if you use Pythonista 3 in another iOS device and place the ids_rsa file.

When connecting to a host, you will notice at least 3 lines from the top will be hidden as StaSh’s shortcut keys and iOS’s software keyboard will use 3 lines of the bottom of your screen. This is very annoying especially when you use ‘vi’ command to edit a file. To avoid this issue, one manual way is to use “stty” command to set your screen size (number of rows) every time you SSH to a server. Refer to examples below and find the best number for your environment.

$ stty rows 51 # Works best for iPad mini 2 + Bluetooth keyboard
$ stty rows 27 # Works best for iPhone 8 Plus with iOS software keyboard
© Peddals.com