Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FongMan

macrumors regular
Original poster
Feb 4, 2006
130
0
Hi Guys,

I need to run a terminal command on my computer at home but it doesn't have screen sharing or remote management enabled. I do however have file sharing enabled and able to browse the drive freely. I want to run a sudo command on that drive but don't know how to run it from where I am. Anybody have any thoughts?
 

MikeDTyke

macrumors 6502a
Sep 7, 2005
661
0
London
Hi Guys,

I need to run a terminal command on my computer at home but it doesn't have screen sharing or remote management enabled. I do however have file sharing enabled and able to browse the drive freely. I want to run a sudo command on that drive but don't know how to run it from where I am. Anybody have any thoughts?

Unless you can use remote desktop or ssh on to your machine, you cannot run anything.

You could in theory do this, if you prepare in advance.

create a cron entry of the sort.

0,15,30,45 * * * * sudo /Users/yourname/scriptname.sh

Then add a sudo alias that doesn't need a password to run. ie.

yourname ALL = NOPASSWD: /Users/yourname/scriptname.sh
WARNING! This is very dangerous, if you mess up the script or someone malicious got access to your fileshare and put that script there with the contents...
rm -fr /

You can say goodbye to your machine.
 

MikeDTyke

macrumors 6502a
Sep 7, 2005
661
0
London
Note you need to replace yourname with whatever your username is and should remove the script file or rename it once it has run.

That cron will run every 15 mins, you might want to adjust it to something more or less often. Also if you ever checked the users mbox file, ie. not your regular email, you'd find a ton of script not found messages.

I can't be sure, but you may not be allowed to have sudo in a cron entry. If that's the case, have a regular script in cron with the contents.
sudo /Users/yourname/someOtherScript.sh
Then change the sudoer privilege above to refer to someOtherScript.sh.

Regards

M. :D
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
If it's your machine then I would turn on remote management and then SSH into the machine and run the command.
 

FongMan

macrumors regular
Original poster
Feb 4, 2006
130
0
Cron huh, never heard of that. Well I have my public IP and everything set ports forwarded. Ok...so that sounds complicated and risky without any guarantees. So is there a way for me to enable Remote Management without actually being by the computer? Changing a plist file or something. I did some research but again the method I found is through Terminal with another Sudo command.
 

FongMan

macrumors regular
Original poster
Feb 4, 2006
130
0
If it's your machine then I would turn on remote management and then SSH into the machine and run the command.

It is my computer but I'm not in town and I'm trying to figure out how to enable it remotely.
 

FongMan

macrumors regular
Original poster
Feb 4, 2006
130
0
Can't I telnet into my computer or something and try a thing? (Don't even know how to Telnet) >.< Such a n00b
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Can't I telnet into my computer or something and try a thing? (Don't even know how to Telnet) >.< Such a n00b

Telnet is just a command, like ssh. You'd need a port to telnet in on that's open already. Same difficulty as SSH. You're essentially needing to hack into your own machine, which means you need to find a security vulnerability in your setup. So if you find something that lets you in, it likely lets other people in and should be closed. I'm not sure of how to make use of the file sharing to get something to execute with sudo privileges.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
It is my computer but I'm not in town and I'm trying to figure out how to enable it remotely.

If your computer hasn't already been configured for remote access, you can't enable remote access from a remote location. That would be a huge security hole. Think about it.
 

FongMan

macrumors regular
Original poster
Feb 4, 2006
130
0
Yes it would be a security hole, but at the same time if you do have it configured it is still pretty hard to get in without the actual password. I guess I was just hoping that I would be able to connect to the computer, open a sharing preferences or remote management file and just adjust a setting. Or if I find a way to run a sudo command remotely then I would be able to do it.
 

BlueRevolution

macrumors 603
Jul 26, 2004
6,054
2
Montreal, QC
You can't execute a file remotely with file sharing. Unfortunately, you'll just have to enable remote login next time you have physical access to the computer. Then you can ssh in and sudo to your heart's content.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.