sudo graphical prompt - passwords

I have a script that must execute a command with root privileges, however I want the script to prompt for the sudo password in a graphical window, not in the terminal. Is this possible?

Try gksu if you use gnome in any Linux flavor.

Related

Can't enter my password when trying to create a Laravel project with Sail on Windows

I want to create a new Laravel 8 project and I followed the documentation with docker and Sail on Windows: https://laravel.com/docs/8.x#getting-started-on-windows
After I installed everything, I tried executing the command to create the project:
curl -s https://laravel.build/example-app | bash
It asked me for my password. I entered it and pressed enter, but nothing happened. When I press CTRL+C, I can see that it tried to execute my password as a command.
run it in WSL command line, not in windows command prompt.
it must work
First of all you should create a folder called projects inside your home directory, then, go into that folder and execute sudo curl -s https://laravel.build/example-app | bash
You could also do sudo su and then curl -s https://laravel.build/example-app | bash
Install Windows Terminal. Open it with your Linux distribution. And try again.

how with putty run a command without any interactivity with the user? [duplicate]

These are the things I need to do:
Open putty.exe
Enter username and password.
Run a shell script.
I am using UFT (VB Scripting). I am able to open PuTTY but not able to enter username and password or run any commands using UFT.
Is there any other way I can achieve this? I have searched it and found that we can use Plink. Then the problem would be that the whole team will have to install Plink for that purpose. And that is not possible.
Thanks in advance.
PuTTY has the -m switch, that you can use to provide a path to a file with a list of commands to execute:
putty.exe user#example.com -m c:\local\path\commands.txt
Where the commands.txt will, in your case, contain a path to your shell script, like:
/home/user/myscript.sh
Though for automation, your better use the Plink command-line connection tool, instead of the GUI PuTTY application, as you have already found out. The Plink is a part of PuTTY package, so everyone who has PuTTY should have Plink too.
The Plink (plink.exe) has the same command-line arguments as PuTTY. And in addition to those, you can specify your command directly on its command like:
plink.exe user#example.com /home/user/myscript.sh
or using its standard input
plink.exe user#example.com < c:\local\path\command.txt
(of course, you will use redirection mechanism of your language, instead of the <).
Note that providing a command using the -m switch or directly on command-line implies a non-interactive mode, while using the standard input uses an interactive mode by default. So the results or behavior may differ. Use the -t and -T switches to force the interactive and the non-interactive mode, respectively.
You can add cmd arguments when you launch putty directly;
start C:\Users\putty.exe -load "server" -l userID -pw Password -m commands.txt
Can you not request the user name and pass prior and pass this along to the executable?
To run a single remote command or short series of commands is even easier by using the plink -batch flag instead of needing a script file. For example to show the OS name and a directory listing, do this:
plink user#host -pw password -batch uname;ls

In command line, putty remote shell doesn't work, but in GUI, it does work

Using the GUI putty.exe, I can connect to my windows server and once it is connected, i can type any command like rename file or mkdir folder and they all work
However, using command line such as
putty -load test -m C:\users\test.txt
or using the GUI putty, but add 1 command to remote command in SSH under Connection, then the command doesn't get executed.
Can anyone explain to me why this is happening or how can i fix this? I am using FreeSSHd on windows 2008 server.
Not sure if this helps, but try adding the /bin/bash directly after your command in the text file. It will keep the window open and you can see what the output of the shell would be if you ran it from the gui.
; /bin/bash
For example if test.txt is running a script
bash myscript.sh
bash myscript.sh; /bin/bash
This is assuming bash.

how to set up the psql command in cygwin?

I have a local dev site on my machine with Apache server and PostgreSQL 9.1 database. As I'm using Windows, I also installed Cygwin. I want to access to database and make some queries via Cygwin insead of pgAdmin III, but it tells me that psql command not found. How should I set up the psql command in cygwin?
As of today, you just have to install postgresql-client package in cygwin:
Run your cygwin setup.exe file (this can be run multiple times to
add more packages).
Type postgresql into the search box, select postgresql-client and
press "next" to install.
Now you can open Cygwin terminal and type psql to run!
The best combo for Cygwin on Windows, I've found, is the normal Windows Postgres installation combined with Cygwin psql.
Cygwin psql (and other command-line tools) can be compiled from source fairly easily. Here's the steps for 9.2.4:
$ wget http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
$ tar xjf postgresql-9.2.4.tar.bz2
$ cd postgresql-9.2.4/
$ ./configure
$ cd src/bin/psql
$ make
This creates a psql.exe binary that works well with Cygwin. However, by default, it tries to connect to the local instance using a Unix socket instead of TCP. So use -h to specify the hostname and force TCP, for example:
$ ./psql -h localhost -U postgres
Move this psql.exe to someplace on your path (e.g. ~/bin) and possibly wrap in a script to add '-h localhost' for convenience when no other arguments supplied.
The source could be modified to change the default, but that takes actual work ;)
If I understand your question correctly you are running cygwin because you want to run queries against PostgreSQL via bash and psql on Windows, right?
Cygwin can run Windows binaries from bash, so install the native Windows builds and make sure psql.exe is in the PATH You should be able to copy the executable if necessary.
There is no need to install a native Cygwin build of PostgreSQL. Just use the existing psql tool, and make sure you can access the Windows-native psql.exe.

How to run a script file remotely using SSH

I want to run a script remotely. But the system doesn't recognize the path. It complains that "no such file or directory". Am I using it right?
ssh kev#server1 `./test/foo.sh`
You can do:
ssh user#host 'bash -s' < /path/script.sh
Backticks will run the command on the local shell and put the results on the command line. What you're saying is 'execute ./test/foo.sh and then pass the output as if I'd typed it on the commandline here'.
Try the following command, and make sure that thats the path from your home directory on the remote computer to your script.
ssh kev#server1 './test/foo.sh'
Also, the script has to be on the remote computer. What this does is essentially log you into the remote computer with the listed command as your shell. You can't run a local script on a remote computer like this (unless theres some fun trick I don't know).
If you want to execute a local script remotely without saving that script remotely you can do it like this:
cat local_script.sh | ssh user#remotehost 'bash -'
It works like a charm for me.
I do that even from Windows to Linux given that you have MSYS installed on your Windows computer.
I don't know if it's possible to run it just like that.
I usually first copy it with scp and then log in to run it.
scp foo.sh user#host:~
ssh user#host
./foo.sh
I was able to invoke a shell script using this command:
ssh ${serverhost} "./sh/checkScript.ksh"
Of course, checkScript.ksh must exist in the $HOME/sh directory.
Make the script executable by the user "Kev" and then remove the try it running through the command
sh kev#server1 /test/foo.sh