Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using the command ssh -i /home/ssh_keys/10_1_1_127 root#10.1.1.127 date for checking the date on some other machine,
If some parameter is wrong, like the user, the ip or the identity file doesn't exists,
ssh asks for password
for example, if I write ssh -i /home/ssh_keys/10_1_1_1277 root#10.1.1.127 date
whilst /home/ssh_keys/10_1_1_1277 doesn't exists, I get:
root#10.1.1.127's password:
I wanted to know if it is possible, and if so, then how to make ssh fail if some parameter isn't right, so ssh won't ask me for a password if I enter wrong parameters...
Thanks
All these changes should be done via root or a sudo enabled user.
In /etc/ssh/sshd_config set the following entries to no:
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
If you need help finding those specific lines, use grep:
grep -n "PasswordAuthentication" /etc/ssh/sshd_config
^^or whatever^^
This outputs the line number
Then restart ssh
/etc/init.d/ssh restart
or
service ssh restart
depending on your flavor of Linux.
Related
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
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"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am writing a bash script for windows powershell.
I am remotely connecting to server by ssh but the problem is connection needs a password and i have to give it by script.
I tried pipelining too by echo "password" | ssh user#remote.host.
But is it still asking for password user#remote.host's password:. Is there any way to enter password by command line or bash script only?
Use ssh-keygen to generate a new SSH key pair, and ssh-copy-id user#machine to copy it to the remote host.
This will let you log in without a password, and it won't introduce any security issues by passing the password as a string.
Use sshpass to pass password to ssh
$ sshpass -p 'password' ssh username#server.example.com
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using a simple shell script on my Linux server which checks if an rsync job is running or if any client accesses some directories from the server via Samba. If this is the case then nothing happens, but if are there no jobs and Samba isn't used than the server goes into hibernation.
Is there any simple command which I can use to check if an SSH connection to the server exists? I want to add this to my shell script so that the server doesn't hibernate if such a connection exists.
Scan the process list for sshd: .
Established connections look something like this: sshd: <username>…
ps -A x | grep [s]shd
should work for you.
use who command
it gives output like
username pts/1 2013-06-19 19:51 (ip)
You could parse that to see how many non locals are added and get their usernames (or there are options see man who for more info
gives a count of how many non localhost users there are
who | grep -v localhost | wc -l
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to access to multiple hosts through SSH, execute a specific command (show ms info) and capture the output to a file. I need to copy that file back to my linux machine
I want to use ssh and expect to supply the password
My problem is saving the output to a text file and looping around 100 machines simultaneously.
It is more straightforward than you think:
host1 $ ssh user#host2 ls > remote-output.txt
Enter passphrase for key '/home/user/.ssh/id_rsa':
host1 $ ls
remote-output.txt
host1 $
To do it for multiple hosts, I suggest using ssh-agent and setting up autorization keys:
$ ssh-agent bash
$ ssh-add
Enter passphrase for /home/user/.ssh/id_rsa:
$ for h in host1 host2;do ssh $h ls > $h.txt; done
$ ls
host1.txt host2.txt
$