MacBook Remote Login Questions and Etc

Dear Apple Community,


I hope this message finds you well. I have a query about the Remote Login feature on MacBook and would appreciate your insights.


In the Sharing settings of MacBook, under “Remote Login,” there is a prompt suggesting that to log in remotely, one should type “ssh user@ip_of_macbook.” Intrigued by this capability, I attempted to create a shortcut on my iPhone to facilitate remote login through a script using SSH keys.


Here are the steps I followed:


1. Successfully created an SSH key and added it to my MacBook’s authentication key.

2. Configured the iPhone shortcut with the following details:

• Host: my_macbook_ip

• Port: 22

• User: my_macbook_username

• Authentication: SSH Key

• SSH key: my_key

• Input: blank

• Script: ssh my_macbook_username@my_macbook_ip


Upon executing the shortcut, it resulted in freezing. I’m beginning to wonder if remote login from an iPhone to a computer is feasible.


I recall a previous method using “osascript” to perform keystrokes for password input, but this no longer works. Despite granting sshd access to disk, automation, and accessibility, osascript remains ineffective.


Any assistance or guidance you can provide would be greatly appreciated.

iPhone SE, iOS 15

Posted on Nov 26, 2023 1:27 AM

Reply

Similar questions

8 replies

Nov 26, 2023 12:07 PM in response to Micah_Gael

Micah_Gael wrote:

I appreciate the insight shared about the limitations of SSH on iPhones. It’s valuable to note that I’m exploring the ‘Run Script over SSH’ feature in the Shortcuts app for specific tasks on my MacBook remotely. If there are any challenges or if further guidance is available regarding this Shortcuts action, I would be grateful for assistance within this context.

That is an advanced topic, even if the iPhone wasn't involved. There are many things that can go wrong. The iPhone will make it impossible to debug the most common problems. There is no way to tell if you've the first part wrong, or any subsequent step, or any step in between. And according to your description of the problem, your script is "ssh my_macbook_username@my_macbook_ip", which is most definitely not any kind of "run script" operation. That is an interactive login operation.


I'm not familiar with the "run script over ssh" shortcut, or shortcuts at all, for that matter. But when I look at it on my phone, I seem to have played around with it before. For the script to run, try something like "ls -al" instead. You should see a listing from your home directory.

Nov 26, 2023 4:53 PM in response to Micah_Gael

You can do multiple things with an ssh connection. The typical operation is an interactive login. If you were using a Mac, trying to connect to some server, you would run something like "ssh my_macbook_username@my_macbook_ip". Once you were logged in, then you could run commands as if you were on the server.


But you can also directly run commands instead of an interactive login. You run one command and it sends the result back and that's it. This is not an interactive session. You are running something like "ssh my_macbook_username@my_macbook_ip ls -al". This makes the ssh connection and then runs "ls -al" and sends the output back.


When you are running via something like a shortcut, especially from a phone, you definitely aren't doing any kind of interactive login. You are just running a command on the server and getting the result. That's all. All of those other setup options are sufficient to make the connection. You don't need the "ssh my_macbook_username@my_macbook_ip" part. All you need it the "ls -al" part. That's what you enter and only that.

Nov 26, 2023 7:55 AM in response to Micah_Gael

I’ve used several different iPhone based terminal emulator apps that include ssh support to ssh into my Macs while I’ve been on my home network. I just used “Termius” to verify it still works.


A) As Etresoft says your screen is tiny.


B) You really need to be familiar with the command line environment to do much with an ssh session into your Mac from an iPhone.


C) If you do not know what you are doing at the command prompt, you can cause lots of damage, that will be difficult or impossible to recover from.


D) You should not play in the command line environment unless you maintain complete backups, and take them on a regular basis.


ssh connections are more useful when they are workstation to workstation and you have a larger screen. They are still a command line environment, but if you are doing things like connecting to remote Linux/Unix systems, it can be useful.


I live in ssh connections developing software on a remote Linux system at work. I’ve been working with terminals and later terminal emulators since the 1970’s and I’m very comfortable in that environment.


You on the other hand might prefer Mac to Mac Screen Sharing or a VNC (Virtual Network Computing) connection. There is a difference macOS setting to allow screen sharing.

Share the screen of another Mac - Apple Support


There are iPhone screen sharing apps and VNC apps available, but if Etresoft thought your iPhone screen was too small for an ssh connection, a screen sharing or VNC connection is 10 times worse.


NOTE: I have rarely used ssh connections from my iPhone, and generally they were 3 am, I do not want to get out of bed, I forgot to do something 5 minute tasks, related to my day job.


I’ve played with iPhone screen sharing/VNC connections, just to prove to myself that they work, but the iPhone is way too small to do anything useful, and if you need the keyboard, you loose 2/5ths of you already small screen to the iPhone virtual keyboard.


It is fun to play with ssh and screen sharing, but not extremely practical.

Nov 26, 2023 2:47 PM in response to etresoft

Yeah, man, this thing is advanced and hard to understand. Also, it’s definitely hard to see why some things won’t work, like the script in the shortcut which is “ssh my_macbook_username@my_macs_ip”. The hard part was when having this action in shortcuts, where you can explore if you want to, there is this part in the action “Run Script Over SSH,” where it says authentication, and you can either choose password or SSH key.


Opting for an SSH key, you receive a public key, e.g., "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB2aWV3IGNvbnRyb2xAd2hhdC5jb20=." To add this key to your MacBook, execute the following command in your MacBook's terminal:


```

echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB2aWV3IGNvbnRyb2xAd2hhdC5jb20=" >> ~/.ssh/authorized_keys

```


This command appends the SSH key to the authorized_keys file in the .ssh directory.


I finished appending the ssh key to my Mac so then additionally, during this process, I tried running the script “ssh my_macbook_username@my_macbook_ip”


But it would not work. So then I tried to debug my script on my iPhone shortcut to see the error, I added -v in the script (Here is the script with -v: ssh -v my_macbook_username@my_macbook_ip.


This helped me a bit and I think the problem was an interaction portion, and I say this because, on the shortcut action, “Runs script over SSH”, interaction portions don’t work so I had to turn off passphrase and password.


But, for some reason it still didn’t work, but for my Mac, turning off these prompts allowed me to successfully run the script


"ssh my_macbook_username@my_macbook_ip", in the MacBook terminal without requiring a password or passphrase. Unfortunately, replicating this success in the Shortcuts app led to it hanging or freezing.

Nov 26, 2023 6:21 AM in response to Micah_Gael

Micah_Gael wrote:

Upon executing the shortcut, it resulted in freezing. I’m beginning to wonder if remote login from an iPhone to a computer is feasible.

No. An iPhone isn't going to be able to do an ssh login. The screen is too tiny. SSH is a Terminal interface. You need a keyboard and a screen to see what's going on. An iPhone isn't going to be able to do that.


Plus, the iPhone doesn't have ssh client software. I'm not sure what you were trying run with that shortcut, but the key piece you need isn't there. You might be able to download some app that offers remote ssh access. Maybe you could run that with a shortcut. But you would still be dealing with keyboard and screen issues.

Nov 26, 2023 10:50 AM in response to etresoft

I appreciate the insight shared about the limitations of SSH on iPhones. It’s valuable to note that I’m exploring the ‘Run Script over SSH’ feature in the Shortcuts app for specific tasks on my MacBook remotely. If there are any challenges or if further guidance is available regarding this Shortcuts action, I would be grateful for assistance within this context.

Nov 26, 2023 10:52 AM in response to Micah_Gael

I want to clarify that my interest lies in using the ‘Run Script over SSH’ action within the Shortcuts app on my iPhone. This action allows me to execute scripts on my MacBook remotely. While I understand the challenges associated with SSH on mobile devices, any assistance or guidance related to utilizing this specific feature in the Shortcuts app would be greatly appreciated. Thank you.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

MacBook Remote Login Questions and Etc

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.