Root user/sudo equivalent in Cygwin?

后端 未结 17 2259
旧时难觅i
旧时难觅i 2020-12-04 04:23

I\'m trying to run a bash script in Cygwin.

I get Must run as root, i.e. sudo ./scriptname errors.

chmod 777 scriptname does no

17条回答
  •  一生所求
    2020-12-04 05:25

    Can't fully test this myself, I don't have a suitable script to try it out on, and I'm no Linux expert, but you might be able to hack something close enough.

    I've tried these steps out, and they 'seem' to work, but don't know if it will suffice for your needs.

    To get round the lack of a 'root' user:

    • Create a user on the LOCAL windows machine called 'root', make it a member of the 'Administrators' group
    • Mark the bin/bash.exe as 'Run as administrator' for all users (obviously you will have to turn this on/off as and when you need it)
    • Hold down the left shift button in windows explorer while right clicking on the Cygwin.bat file
    • Select 'Run as a different user'
    • Enter .\root as the username and then your password.

    This then runs you as a user called 'root' in cygwin, which coupled with the 'Run as administrator' on the bash.exe file might be enough.

    However you still need a sudo.

    I faked this (and someone else with more linux knowledge can probably fake it better) by creating a file called 'sudo' in /bin and using this command line to send the command to su instead:

    su -c "$*"
    

    The command line 'sudo vim' and others seem to work ok for me, so you might want to try it out.

    Be interested to know if this works for your needs or not.

提交回复
热议问题