Mac Remote Shell

3

I am trying to create a remote shell on OS X with NC.

I tried nc -l 1337 -e /bin/bash but it seems that the Mac version of NC does not support the -e option.

Does anyone know how I can achieve a remote shell on OS X preferably only using the built in tools?

Unfortunately SSH isn't an option. What I am doing has to be done solely from the command line (so GUI option alterations are out of the question). Also I am trying to avoid password's because it will cause problems for my client program.

EDIT: Apologies for lack of information. I thought I had added enough.

Basically, I have several VM's running OS X and need them to have able to use each others command line. My plan was to have NC running on each and the the main VM could send commands to them through a PHP script.

Also, the reason for wanting to use the build in commands/tools is because I this will eventually be run on physical hardware and Mac's will be added and removed regularly and I do not want to install new software on client machines.

The reason for avoiding GUI actions is that this will be run without supervision of myself and am trying to make this as seamless as possible. When a machine is connected, I am able to launch one command, and I need to do many commands and file transfers which is why a remote shell is what I am after.

Jamescun

Posted 2010-04-28T20:37:25.010

Reputation: 133

I just looked at rsh and it doesn't seem to do what I am trying to do, which is create a listening server which I can connected to and receive full command line access. – Jamescun – 2010-04-28T20:44:36.320

7Is there anything particularly wrong with using the built-in SSH server? – Ignacio Vazquez-Abrams – 2010-04-28T20:53:44.167

@arjan: i expect he means netcat

– quack quixote – 2010-04-28T21:10:12.447

Still wondering about "one command". So, one line with multiple commands (separated with ;, or chained using || or &&) is not possible either? – Arjan – 2010-04-28T22:17:21.297

(@Jamza, did you see my comment about chaining commands?) – Arjan – 2010-04-30T05:24:49.410

Answers

2

The usual way is to enable the ssh service for command line access.

The very Mac way to do this:

  1. Go to Sytem Preferences App
  2. Choose Sharing
  3. Check "Remote Login" checkbox

You should now be able to connect using any standard ssh client. Macs and linux/unix machines have it built in. PuTTY is a good choice on Windows.

Doug Harris

Posted 2010-04-28T20:37:25.010

Reputation: 23 578

Unfortunately SSH isn't an option.

What I am doing has to be done solely from the command line (so GUI option alterations are out of the question). Also I am trying to avoid password's because it will cause problems for my client program. – Jamescun – 2010-04-28T20:59:17.727

1You use System Preferences to enable SSH. You do that once. After that, you use the ssh command from Terminal. ssh does not require passwords; the preferred security measure is public/private keys. If you do not have access to the GUI and need to enable command-line access, I refuse to help. – Nate – 2010-04-28T21:01:53.790

2@Jamza: You really should consider putting important details such as these in the original question so that people don't have to keep guessing what you want. – Ignacio Vazquez-Abrams – 2010-04-28T21:02:19.077

As Nate points out, the GUI involvement is a one time action. – Doug Harris – 2010-04-28T21:17:04.383

You can enable SSH on a Mac from the command line: sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist – Gordon Davisson – 2010-04-29T06:29:24.013

2

Well The Problem you are having with NC ( assuming you are talking about NETCAT) the Apple Version does not have the -e option in its bin.

The best solution is, to Compile a GNU version of NC using the apple SDK, then replace the apple version with your own GNU NC version. as far as i know apple has no plans to add the -e option to appleNC.

I had to do this for a few apple daemons that were ...lacking.

hope this helps

Lightly Salted

Posted 2010-04-28T20:37:25.010

Reputation: 777

1Don't Fear the ./Make – Lightly Salted – 2010-04-28T21:30:00.473

1

First off, nc (which I had no prior knowledge of) appears to be a kind of telnet program. Insecure at best and rather rudimentary. I would not advise trying to use it.

Second, you have failed to adequately describe what you're trying to do. Are you trying to remotely login to a Mac OS X computer from another computer? Are you trying to remote from the OS X computer to another? Are you trying to create some sort of remote server that's accessible externally?

Why can't you use SSH? Why can you adjust things via the system preferences?

Josh K

Posted 2010-04-28T20:37:25.010

Reputation: 11 754

netcat is probably more akin to ping than telnet ... it's a low-level TCP/UDP swiss army knife, so security isn't really netcat's concern. – quack quixote – 2010-04-28T21:21:31.987

The problem with SSH is that it will require the users password, and pretty much everything will be going on in the background. – Jamescun – 2010-04-28T21:26:00.527

2@Jamza You can setup ssh keys so that no password is necessary. – KeithB – 2010-04-29T02:01:38.050

1

Unfortunately SSH isn't an option. What I am doing has to be done solely from the command line

You can enable SSH access using sshd, or /usr/sbin/sshd -p 1337 to listen to a non-privileged port (hence not requiring a sudo password).

Arjan

Posted 2010-04-28T20:37:25.010

Reputation: 29 084

The problem with that was it requires root and the users password.

The reason netcat seemed the best option was because it was there by default, did not require root and was a single command.

The controlling server does not know any of the machines passwords. – Jamescun – 2010-04-28T21:43:33.937

@Jamza, ah, right, that still needs sudo, unless maybe if you're willing to open a different port? – Arjan – 2010-04-28T21:54:00.137

@Jamza, can you get a public certificate on those machines? – Arjan – 2010-04-28T21:57:12.827

Unfortunately not, All I have to start off with is to launch one command and what I want to do is create a remote shell so I can launch more commands and copy files (e.g. adding public certificates). The reason SSH is a problem, I or the control server does not know the users password, so cannot authenticate. – Jamescun – 2010-04-28T22:05:03.650

1

If you set up an SSH keys (for instance with "ssh-keygen -t rsa") with no passphrase and then put the public key (as found in ~/.ssh/id_rsa.pub) in the ~/.ssh/authorized_hosts file in the remote user's host, then you won't need to exchange any passwords and everything can be done from the command line using ssh.

Marnix A. van Ammers

Posted 2010-04-28T20:37:25.010

Reputation: 1 978

Too bad Jamza cannot put such keys on the remote machines... – Arjan – 2010-04-29T04:54:36.767