Paste multiple commands to Putty - process serially? - putty

I have about 3000 individual commands that I need to execute on a system via Putty. I am doing this by copying ~100 of the commands and pasting them into a putty SSH session. It works, however the issue is that Putty does not process them serially and the output gets garbled.
Is there a way to make Putty process each command, wait for a return and then process the next? The Windows command prompt does this and I'm thinking there is a way to do so with Putty.
Yes, I know I could put this in a bash script, but due to circumstance outside my control, this has to be done using SSH and in a manner that can be monitored as we go and logged.

I do this all the time. Put your commands in a ( ) block, which will run it as a subshell, perfectly everything within serially. I'm running Windows PuTTY and connecting to Linux and AIX servers. Try it.
(
Command1
Command2
Command3
)
In practice, I might have a huge load of many 100s of statements I want to run, in Notepad++ or whatever. So I copy them to clipboard, and then in PuTTY:
(
paste in your wad here
)
EDIT: If you want to log the output from each of your statements individually, you might do something like this:
(
Command1 > /home/jon/command1output.txt
Command2 > /home/jon/command2output.txt
Command3 > /home/jon/command3output.txt
)
or if you just want one big stream of output, you could interleave separators for easier reading later:
(
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command1 ..."
Command1
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command2 ..."
Command2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command3 ..."
Command3
)
EDIT2: Another variation using an inline function. All paste-able into PuTTY, with perfect serial running, logging as command1:output1,command2:output2,... , and capable of driving SQL*Plus.
(
function geniusMagic() {
echo " "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
date
echo "RUNNING COMMAND:"
echo " "
echo "$*"
echo " "
echo "OUTPUT:"
echo " "
sh -c "$*"
}
geniusMagic df -m /home
geniusMagic 'printf $RANDOM | sed "s/0//g"'
geniusMagic 'echo "select count(*)
FROM all_tables;
" | sqlplus -s scott/tiger'
)
Sample output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
df -m /home
OUTPUT:
Filesystem MB blocks Free %Used Iused %Iused Mounted on
/dev/hd1 1024.00 508.49 51% 3164 3% /home
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
printf $RANDOM | sed "s/0//g"
OUTPUT:
2767
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
echo "select count(*)
FROM all_tables;
" | sqlplus -s scott/tiger
OUTPUT:
COUNT(*)
----------
48

Just an idea here, Putty comes with a command-line tool called Plink. You could write a script on your windows machine that creates a connection to the remote server with Plink, then parses your list of commands one at a time and sends them.
This should look exactly the same to the remote server (which I assume is what's doing the logging), while letting you have a bit more control than copy-pasting blocks of commands.

I'm not sure why you could not use Plink, but you could make a batch file with Notepad++.
plink <hostname> -l <login_name> -pw <password> <command 1>
plink <hostname> -l <login_name> -pw <password> <command 2>
plink <hostname> -l <login_name> -pw <password> <command 3>
...
plink <hostname> -l <login_name> -pw <password> <command 3000>
Run the batch file:
filename.bat > log.txt 2>&1
Notepad++: http://notepad-plus-plus.org/
Plink: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Batch files: http://www.robvanderwoude.com/batchfiles.php
Display & Redirect Output: http://www.robvanderwoude.com/battech_redirection.php

Maybe the answer you are looking for is here.
Here a copy of the answer I think may be interesting for you :
// Wait for backup setting prompt
Repeat Until %D1% = 1
Activate Window: "DAYMISYS1.qdx.com - PuTTY"
Mouse Move Window 12, 11 <------- Moves mouse to upper left corner to activate menu options
Mouse Right Button Click
Delay 0.1 Seconds
Text Type: o <------- Activates Copy All to Clipboard command
Delay 0.2 Seconds
If Clipboard Contains "or select a number to change a setting:" <------- Look for text of prompt that I am waiting for
Repeat Exit <------- If found, exit loop and continue macro
End If
Delay 1 Seconds <------- If prompt is not found, continue loop
Repeat End

In the putty I have, I just paste into it and it works.
Open notepad
Type out your list of commands
Highlight notepad
ctr + c (or right click, copy)
click on your putty window
right-click once, into where you type your commands
You should see all of the commands inserted into your entry box
hit enter
Note: I used this to enter multiple lines into cin prompts from C++ program compiled on linux. I don't know if it will work directly into the terminal.

Related

Issue in running my interactive bash script on remote server by doing ssh and with sshpass if VPN disconnects

I am trying to run my interactive bash script kept on remote machine from my local machine.this script can take 4-5 hours to run hence need to run it on screen or nohup so that even if vpn disconnects it doesn't stop my script from running.
here is my command which I run from local.
sshpass -p <Mypassword> ssh -t user#hostaname.com "cd /directory/ ; ./runscr.sh ; bash --login"
my runscr.sh contains following
now=$(date +"%s")
screen -t $now bash ./mainscript.sh bash
trying to run main script in screen /I am open to try nohup as well if it works.
mainscript.sh takes input for 2 parameters and then starts executing some further processing (taken input and for that input extracts data from the main 300gb file, for this zgrep, split and for loop is used in bash which does not have any issue, just it takes some 3-4 hours)
read -p 'please enter Input 1 : ' cname
read -p 'please enter Input 2 : ' cid
echo Thankyou entered cname is $cname and entered cd is $cid we now have the details .starting zgrep commands to extract above cname and cide from main 300gb file.
.
.
.
.
further code with grep,split and loop commands
this works fine till vpn is not disconnected, but once vpn is disconnected it stops processing.
what can I do so that even if vpn disconnected it keeps processing and generated th output

Send echo command to an external xTerm

I have a bash script, and I want to be able to keep a log in an xterm, and be able to send echo to it anytime.
How would I do this?
Check the GPG_TTY variable in your xterm session. It should have the value similar to
GPG_TTY=/dev/pts/2
This method should be available for terminals that support GNU Pinentry.
Another option to determine the current terminal name is to use
readlink /proc/self/fd/0
The last method applies only to Linux
Now if your bash script implements a command
echo "Hello, world!" > /dev/pts/2
This line should appear on the xterm screen.
I managed to make a console by running an xterm with a while loop clearing the screen, reading the contents of the log file, pauseing for a second, then looping again. Here was the command:
xterm -T Console -e "while true: do cls && cat ${0}-LOG.txt && sleep 1; done"
Then to send something to the console:
echo -e "\e[91;1mTest" >> ${0}-LOG.txt
And the console will update each second.

plink won't return to command prompt

I try to execute a bash script via plink. Script looks something like this:
echo "# Starting process..."
./bin/process "process.cfg" &
disown %1
echo "# Done!"
When i execute this script in a terminal on linux, everything works fine. After the "Done!" line I get a command prompt (as expected).
Now when I run this script via plink, the output stops afyer the "Done!" line, but plink won't return to the command prompt and "hangs" until +c.
The script is placed in a file and given to plink with the -m parameter
I tried addind 'logout', 'exit', 'set -e' at the end of the script, but it doesn't help. Also adding -batch, -T or -N to the plink command brought no success.
Any ideas on how to fix this?
Ok, it seems I had to detach stdout/err from the terminal.
In a normal terminal this wouldn't matter ofcourse, but plink remained in a "busy" state because of this.
So, inside my bash script (which executed the command) I had to change:
./bin/process "process.cfg" &
to:
./bin/process "process.cfg" /dev/null 2>&1 &
plink now returns the correct "finished" state at the end of the bash script.
plink.exe -P PORT_NUM -v USERNAME#HOST_IP -pw PASSWD "COMMAND >/dev/null &"
& would move your process to the background
> /dev/null allows your command run silently by getting stdout/stderr to output to a dummy null device
note: the shell command is wrapped in "double quotations"
Plink has a -batch parameter which disable all interactive prompts. It may be what you need here to avoid hanging until ctrl-C.

plink truncating commands

I'm using plink.exe on WinXP to run some commands on Z/OS BASH. My commands are interspersed with echo commands so that I can parse the output and work out what is where. The first dozen or so commands run fine, but then one of them gets truncated.
For example:
echo :end_logdetail:
echo Job Name : TfmMigration
echo :jobinfo:
What happens:
user#host:/dev> echo :end_logdetail:
:end_logdetail:
user#host:/dev> echo Job Name : Tf
Job Name : Tf
user#host:/dev> echo :jobinfo:
:jobinfo:
I just checked where in the input file the error occurs, and it's exactly 4444 bytes in, on line 116 (so it's done 115 successful commands before it goes wrong). The command I'm using is:
Code:
plink -batch -pw xxxx user#host < "c:\dev\telnetcmd.txt" > "c:\dev\telnetout.txt"
The telnetcmd.txt is just a DOS text file with an "exit" command at the end.
Any idea why one of my commands is being truncated in this way?
Update: I don't get the problem if I pass the command file to plink with -m, only when I feed it in with the < operator.
As shellter points out, I should have been using the -m option. This does mean that (unlike the telnet solution that I was using) my commands do not show up in the output, and neither do the shell prompts, but I can manage without those.

Root user/sudo equivalent in Cygwin?

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 nothing to help.
I've looked for ways to imitate sudo on Cygwin, to add a root user, since calling "su" renders the error su: user root does not exist, anything useful, and have found nothing.
Anyone have any suggestions?
I answered this question on SuperUser but only after the OP disregarded the unhelpful answer that was at the time the only answer to the question.
Here is the proper way to elevate permissions in Cygwin, copied from my own answer on SuperUser:
I found the answer on the Cygwin mailing list. To run command with elevated privileges in Cygwin, precede the command with cygstart --action=runas like this:
$ cygstart --action=runas command
This will open a Windows dialogue box asking for the Admin password and run the command if the proper password is entered.
This is easily scripted, so long as ~/bin is in your path. Create a file ~/bin/sudo with the following content:
#!/usr/bin/bash
cygstart --action=runas "$#"
Now make the file executable:
$ chmod +x ~/bin/sudo
Now you can run commands with real elevated privileges:
$ sudo elevatedCommand
You may need to add ~/bin to your path. You can run the following command on the Cygwin CLI, or add it to ~/.bashrc:
$ PATH=$HOME/bin:$PATH
Tested on 64-bit Windows 8.
You could also instead of above steps add an alias for this command to ~/.bashrc:
# alias to simulate sudo
alias sudo='cygstart --action=runas'
You probably need to run the cygwin shell as Administrator. You can right click the shortcut and click run as administrator or go into the properties of the shortcut and check it in the compatability section. Just beware.... root permissions can be dangerous.
Building on dotancohen's answer I'm using an alias:
alias sudo="cygstart --action=runas"
Works as a charm:
sudo chown User:Group <file>
And if you have SysInternals installed you can even start a command shell as the system user very easily
sudo psexec -i -s -d cmd
I found sudo-for-cygwin, maybe this would work, it is a client/server application that uses a python script to spawn a child process in windows (pty) and bridges user's tty and the process I/O.
It requires python in windows and Python modules greenlet, and eventlet in Cygwin.
It seems that cygstart/runas does not properly handle "$#" and thus commands that have arguments containing spaces (and perhaps other shell meta-characters -- I didn't check) will not work correctly.
I decided to just write a small sudo script that works by writing a temporary script that does the parameters correctly.
#! /bin/bash
# If already admin, just run the command in-line.
# This works on my Win10 machine; dunno about others.
if id -G | grep -q ' 544 '; then
"$#"
exit $?
fi
# cygstart/runas doesn't handle arguments with spaces correctly so create
# a script that will do so properly.
tmpfile=$(mktemp /tmp/sudo.XXXXXX)
echo "#! /bin/bash" >>$tmpfile
echo "export PATH=\"$PATH\"" >>$tmpfile
echo "$1 \\" >>$tmpfile
shift
for arg in "$#"; do
qarg=`echo "$arg" | sed -e "s/'/'\\\\\''/g"`
echo " '$qarg' \\" >>$tmpfile
done
echo >>$tmpfile
# cygstart opens a new window which vanishes as soon as the command is complete.
# Give the user a chance to see the output.
echo "echo -ne '\n$0: press <enter> to close window... '" >>$tmpfile
echo "read enter" >>$tmpfile
# Clean up after ourselves.
echo "rm -f $tmpfile" >>$tmpfile
# Do it as Administrator.
cygstart --action=runas /bin/bash $tmpfile
Or install syswin package, which includes a port of su for cygwin: http://sourceforge.net/p/manufacture/wiki/syswin-su/
This answer is based off of another answer. First of all, make sure your account is in the Administrators group.
Next, create a generic "runas-admin.bat" file with the following content:
#if (1==1) #if(1==0) #ELSE
#echo off&SETLOCAL ENABLEEXTENSIONS
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
cscript //E:JScript //nologo "%~f0" %*
#goto :EOF
)
FOR %%A IN (%*) DO (
"%%A"
)
#goto :EOF
#end #ELSE
args = WScript.Arguments;
newargs = "";
for (var i = 0; i < args.length; i++) {
newargs += "\"" + args(i) + "\" ";
}
ShA=new ActiveXObject("Shell.Application");
ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+" "+newargs+"\"","","runas",5);
#end
Then execute the batch file like this:
./runas-admin.bat "<command1> [parm1, parm2, ...]" "<command2> [parm1, parm2, ...]"
For exaxmple:
./runas-admin.bat "net localgroup newgroup1 /add" "net localgroup newgroup2 /add"
Just make sure to enclose each separate command in double quotes. You will only get the UAC prompt once using this method and this procedure has been generalized so you could use any kind of command.
A new proposal to enhance SUDO for CygWin from GitHub in this thread, named TOUACExt:
Automatically opens sudoserver.py.
Automatically closes sudoserver.py after timeout (15 minutes default).
Request UAC elevation prompt Yes/No style for admin users.
Request Admin user/password for non-admin users.
Works remotely (SSH) with admin accounts.
Creates log.
Still in Pre-Beta, but seems to be working.
I landed here through google, and I actually believe I've found a way to gain a fully functioning root promt in cygwin.
Here are my steps.
First you need to rename the Windows Administrator account to "root"
Do this by opening start manu and typing "gpedit.msc"
Edit the entry under
Local Computer Policy > Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options > Accounts: Rename administrator account
Then you'll have to enable the account if it isn't yet enabled.
Local Computer Policy > Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options > Accounts: Administrator account status
Now log out and log into the root account.
Now set an environment variable for cygwin. To do that the easy way:
Right Click My Computer > Properties
Click (on the left sidebar) "Advanced system settings"
Near the bottom click the "Enviroment Variables" button
Under "System Variables" click the "New..." button
For the name put "cygwin" without the quotes.
For the value, enter in your cygwin root directory. ( Mine was C:\cygwin )
Press OK and close all of that to get back to the desktop.
Open a Cygwin terminal (cygwin.bat)
Edit the file /etc/passwd
and change the line
Administrator:unused:500:503:U-MACHINE\Administrator,S-1-5-21-12345678-1234567890-1234567890-500:/home/Administrator:/bin/bash
To this (your numbers, and machine name will be different, just make sure you change the highlighted numbers to 0!)
root:unused:0:0:U-MACHINE\root,S-1-5-21-12345678-1234567890-1234567890-0:/root:/bin/bash
Now that all that is finished, this next bit will make the "su" command work. (Not perfectly, but it will function enough to use. I don't think scripts will function correctly, but hey, you got this far, maybe you can find the way. And please share)
Run this command in cygwin to finalize the deal.
mv /bin/su.exe /bin/_su.exe_backup
cat > /bin/su.bat << "EOF"
#ECHO OFF
RUNAS /savecred /user:root %cygwin%\cygwin.bat
EOF
ln -s /bin/su.bat /bin/su
echo ''
echo 'All finished'
Log out of the root account and back into your normal windows user account.
After all of that, run the new "su.bat" manually by double clicking it in explorer. Enter in your password and go ahead and close the window.
Now try running the su command from cygwin and see if everything worked out alright.
Being unhappy with the available solution, I adopted nu774's script to add security and make it easier to setup and use. The project is available on Github
To use it, just download cygwin-sudo.py and run it via python3 cygwin-sudo.py **yourcommand**.
You can set up an alias for convenience:
alias sudo="python3 /path-to-cygwin-sudo/cygwin-sudo.py"
Use this to get an admin window with either bash or cmd running, from any directories context menue. Just right click on a directory name, and select the entry or hit the highlited button.
This is based on the chere tool and the unfortunately not working answer (for me) from link_boy. It works fine for me using Windows 8,
A side effect is the different color in the admin cmd window. To use this on bash, you can change the .bashrc file of the admin user.
I coudln't get the "background" version (right click into an open directory) to run. Feel free to add it.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash]
#="&Bash Prompt Here"
"Icon"="C:\\cygwin\\Cygwin.ico"
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash\command]
#="C:\\cygwin\\bin\\bash -c \"/bin/xhere /bin/bash.exe '%L'\""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash_root]
#="&Root Bash Prompt Here"
"Icon"="C:\\cygwin\\Cygwin.ico"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash_root\command]
#="runas /savecred /user:administrator \"C:\\cygwin\\bin\\bash -c \\\"/bin/xhere /bin/bash.exe '%L'\\\"\""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_cmd]
#="&Command Prompt Here"
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_cmd\command]
#="cmd.exe /k cd %L"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_cmd_root]
#="Roo&t Command Prompt Here"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_cmd_root\command]
#="runas /savecred /user:administrator \"cmd.exe /t:1E /k cd %L\""
A very simple way to have a cygwin shell and corresponding subshells to operate with administrator privileges is to change the properties of the link which opens the initial shell.
The following is valid for Windows 7+ (perhaps for previous versions too, but I've not checked)
I usually start the cygwin shell from a cygwin-link in the start button (or desktop).
Then, I changed the properties of the cygwin-link in the tabs
/Compatibility/Privilege Level/
and checked the box,
"Run this program as an administrator"
This allows the cygwin shell to open with administrator privileges and the corresponding subshells too.
I met this discussion looking for some details on the sudo implementation in different operating systems. Reading it I found that the solution by #brian-white (https://stackoverflow.com/a/42956057/3627676) is useful but can be improved slightly. I avoided creating the temporary file and implemented to execute everything by the single script.
Also I investigated the next step of the improvement to output within the single window/console. Unfortunately, without any success. I tried to use named pipes to capture STDOUT/STDERR and print in the main window. But child process didn't write to named pipes. However writing to a regular file works well.
I dropped any attempts to find the root cause and left the current solution as is. Hope my post can be useful as well.
Improvements:
no temporary file
no parsing and reconstructing the command line options
wait the elevated command
use mintty or bash, if the first one not found
return the command exit code
#!/bin/bash
# Being Administrators, invoke the command directly
id -G | grep -qw 544 && {
"$#"
exit $?
}
# The CYG_SUDO variable is used to control the command invocation
[ -z "$CYG_SUDO" ] && {
mintty="$( which mintty 2>/dev/null )"
export CYG_SUDO="$$"
cygstart --wait --action=runas $mintty /bin/bash "$0" "$#"
exit $?
}
# Now we are able to:
# -- launch the command
# -- display the message
# -- return the exit code
"$#"
RETVAL=$?
echo "$0: Press to close window..."
read
exit $RETVAL
Based on #mat-khor's answer, I took the syswin su.exe, saved it as manufacture-syswin-su.exe, and wrote this wrapper script. It handles redirection of the command's stdout and stderr, so it can be used in a pipe, etc. Also, the script exits with the status of the given command.
Limitations:
The syswin-su options are currently hardcoded to use the current user. Prepending env USERNAME=... to the script invocation overrides it. If other options were needed, the script would have to distinguish between syswin-su and command arguments, e.g. splitting at the first --.
If the UAC prompt is cancelled or declined, the script hangs.
.
#!/bin/bash
set -e
# join command $# into a single string with quoting (required for syswin-su)
cmd=$( ( set -x; set -- "$#"; ) 2>&1 | perl -nle 'print $1 if /\bset -- (.*)/' )
tmpDir=$(mktemp -t -d -- "$(basename "$0")_$(date '+%Y%m%dT%H%M%S')_XXX")
mkfifo -- "$tmpDir/out"
mkfifo -- "$tmpDir/err"
cat >> "$tmpDir/script" <<-SCRIPT
#!/bin/env bash
$cmd > '$tmpDir/out' 2> '$tmpDir/err'
echo \$? > '$tmpDir/status'
SCRIPT
chmod 700 -- "$tmpDir/script"
manufacture-syswin-su -s bash -u "$USERNAME" -m -c "cygstart --showminimized bash -c '$tmpDir/script'" > /dev/null &
cat -- "$tmpDir/err" >&2 &
cat -- "$tmpDir/out"
wait $!
exit $(<"$tmpDir/status")
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.
What I usually do is have a registry "Open Here" helper in order to open a cygwin shell with administrative privileges quite easy from anywhere in my computer.
Be aware you have to have the cygwin "chere" package installed, use "chere -i -m" from an elevated cygwin shell first.
Assuming your cygwin installation is in C:\cygwin...
Here's the registry code:
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash]
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash]
#="Open Cygwin Here as Root"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash\command]
#="c:\\cygwin\\bin\\mintty.exe -i /Cygwin-Terminal.ico -e /bin/xhere /bin/bash.exe"
[-HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
#="Open Cygwin Here as Root"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
#="c:\\cygwin\\bin\\mintty.exe -i /Cygwin-Terminal.ico -e /bin/xhere /bin/bash.exe"
[-HKEY_CLASSES_ROOT\Drive\shell\cygwin_bash]
[HKEY_CLASSES_ROOT\Drive\shell\cygwin_bash]
#="Open Cygwin Here as Root"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\shell\cygwin_bash\command]
#="c:\\cygwin\\bin\\mintty.exe -i /Cygwin-Terminal.ico -e /bin/xhere /bin/bash.exe"
Hope this helps. Let me know if it works for you. Thanks.
PS: You can grab this code, copy and paste it and save it in a name.reg file to run it... or you can manually add the values.
Just simplifying the accepted answer, copy past the below in a Cygwin terminal and you are done:
cat <<EOF >> /bin/sudo
#!/usr/bin/bash
cygstart --action=runas "\$#"
EOF
chmod +x /bin/sudo
Try:
chmod -R ug+rwx <dir>
where <dir> is the directory on which you
want to change permissions.

Resources