Bash script check permissions to run command on remote [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a local development machine and from my bash script am sending commands to the remote server.
How can I write bash code to check if I am allowed to run the remote command so that I can handle the success/failure response from my script?
Alternatively, how can I capture the output so that I can parse it and detect if it succeeded. The difficulty with parsing is that the ssh command might trigger a password prompt so I can't interfere with that.
That bash script uses ssh -qt to send the remote commands
Command
ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php"
Output:
[sudo] password for xxx:
Sorry, user xxx is not allowed to execute '/usr/local/bin/php /mnt/data/script.php' as www on host.domain.com

Assuming that user != root above: you can't - there's no way to read /etc/sudoers or /etc/sudoers.d/* in a normally set-up Linux box if you're not root, so apart from trial & error there's nothing to be done.
As for capturing the result - that's fairly simple (parsing it, of course, is a different story, depending on what you're doing over there).
output=$( ssh user#host -qt "sudo -u www /usr/local/bin/php /mnt/data/script.php" 2>&1 )
After the execution (and you typing the password for sudo)
echo $? # gives you the return-code of what happened on the far end, if it's a success that should be 0
echo $output # gives you the strings to parse

Related

Got error "passwords do not match" using passwd in docker [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I wanna create a user had random password for FTP in Docker. The section of Dockerfile like below:
RUN useradd web
RUN export ftppass=`cat /proc/sys/kernel/random/uuid`
RUN echo -e "$ftppass\n$ftppass" | passwd web
But I got an error in last line:
New password: Retype new password: Sorry, passwords do not match.
passwd: Authentication token manipulation error
passwd: password unchanged
Why the passwords do not match even I using a same variable?
update:
I found the output of echo -e "$ftppass\n$ftppass" is:
Step 9/15 : RUN echo -e "$ftppass\n$ftppass"
---> Running in ddd97df41d85
-e
Removing intermediate container ddd97df41d85
---> a64b606ea898
Step 10/15 : ...
Why it's not works for echo -e and where are my $ftppass?
Resolved, the new section of Dockerfile is:
RUN useradd web
RUN cat /proc/sys/kernel/random/uuid > /etc/vsftp-password
RUN echo "web:"`cat /etc/vsftp-password` | chpasswd
RUN echo "ftp info web:"`cat /etc/vsftp-password`
Thanks anyone and happy new year~
Instead of using passwd in a creative way, you should rather look at its manual page, which mentions chpasswd in the See Also section.
The passwd command is meant for interactive use, and it doesn't read its input like most other programs, since the input is not echoed to the screen.

Issue with changing login shell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to change the default login shell on my Ubuntu.
To change the shell I ran the following:
$ chsh -s /usr/bin/zsh
After that I restart my terminal but my default shell is still bash.
$ echo $SHELL
/bin/bash
These are shells installed on my machine:
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/zsh
/usr/bin/zsh
Record for my user in /etc/passwd is also changed like expected:
$ cat /etc/passwd|grep myuser
myuser:x:1000:1000:myuser,,,:/home/myuser:/usr/bin/zsh
I successfully changed my login shell the same way on my mac but I seem to be having some issue on Ubuntu. Am I missing something here?
You need to logout and log back into Ubuntu so that your GUI based X terminal shells pick up the new shell value.
Note: Ctrl+Alt+F[1-6] represent 6 virtual shells while GUI login is on Ctrl+Alt+F7

How to copy files over ssh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
How do I copy a file using ssh from my test server to my production server, how do I do this for a single file and how do I do this for multiple files?
From Window to Linux
Download https://cygwin.com/ this will give you a proper terminal which will then allow you to run the linux commands as listed below in the From Linux to Linux section.
From Linux to Linux
The essential command is this
The command
scp [ssh login to remote server]:[filepath] [local filepath]
To copy a single file example
scp user#your.server.example.com:/path/to/foo/[filename] /home/user/Desktop/[filename]
To copy a directory example
scp -r user#your.server.example.com:/path/to/foo /home/user/Desktop/
To use full power of scp you need to go through next steps:
Setup public key authentication
Create ssh aliases
Then, for example if you'll have this ~/.ssh/config:
Host test
User testuser
HostName test-site.com
Port 22022
Host prod
User produser
HostName production-site.com
Port 22022
you'll save yourself from password entry and simplify scp syntax like this:
scp -r prod:/path/foo /home/user/Desktop # copy to local
scp -r prod:/path/foo test:/tmp # copy from remote prod to remote test
More over, you will be able to use remote path-completion:
scp test:/var/log/ # press tab twice
Display all 151 possibilities? (y or n)

Got an error while executing bash commands on remote ubuntu machine "no tty present and no askpass program specified" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm running a bash script to execute a command on a remote host. Here is the command:
ssh ppuser#10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"
$1 and $2 are command line arguments. But while executing I'm getting this error : no tty present and no askpass program specified.
Hope you will help me, any help would be greatly appreciated. Thank You.
Somewhere in your sudoers file you have following
Defaults requiretty
Just comment this line - remove it. Or
Defaults !requiretty
For specific program name you can also attempt following:
Defaults </path to program> requiretty
change it to
Defaults </path to program> ! requiretty
Specific to user you can add
Defaults:username !requiretty
Adding What already have been specified in comment,
For the same you will have to
user-name ALL=(ALL) NOPASSWD: ALL
Its for passwordless sudo
Looks like you are invoking sudo, and it is not working because it doesn't have a tty bound. add
"Defaults visiblepw"
in sudoers file enables sudo even if a console doesn't allocate a tty. Use visudo on the remote machine to add this and see if this helps.
Try this command
sshpasss -p password ssh ppuser#10.101.5.91 "sudo mv /tmp/$2.tar.gz $1"

Loging with SSH with a different user, shows no current path [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I am trying to get a server up and running, there is no problem when I am using my root user, however when I created a new user and I log in with him instead of getting
user#internet:/$
I am only geting $ and I can't see the folder in which I am.
The server is running ubuntu if that helps.
Your new user is probably using a different shell. You can check by typing $0 at the prompt in each.
It sounds like root is using bash and your new user is using sh, but do the above to check.
If you want to modify the login shell for your new user, use usermod with the -s flag:
usermod user -s /bin/bash
The above would set the default shell to bash.
It's because your user runs sh as default shell.
Run as root:
chsh -s /bin/bash your_user
And login again.

Resources