I'm trying to create a script to remotely reboot a device over an ssh connection.
The problem is that the reboot command needs user confirmation before executing, so I need to send the letter "y".
This is a Linux based device but it's customized by the manufacturer, so most of Linux commands do not work and it's not possible to install any additional packages.
This is what happen when I send the reboot command:
xxx > reboot
You have chosen to reboot.
Do you want to continue (y/N)?
This is the part of the script where the connection to the device is made and the command is sent
ssh -t root#10.0.16.20 << EOF
reboot
EOF
How can I send the letter "y" in that connection?
Related
I have an expect script which runs ssh and eventually results in a shell. Is it possible to run this script whenever someone ssh's to the matching machine, instead of just using ssh? (ideally by setting some config in ~/.ssh/config)
I'd prefer not to create an alias/script for ssh to check what the host is, then run the appropriate shell.
I'm trying to set up my remote server so that I can ssh in, start a python process, then detach, logout, and shut down my local computer. I've been able to do this before using nested tmux sessions:
local host - tmux - ssh into remote
remote host - tmux - start python process - detach remote tmux
"exit" from the remote host and close down the remote session.
This was working just fine for me. I can detach the remote session, close down ssh, shut down everything locally, then boot up, relogin via ssh, and then reattach the remote tmux session.
My issue is that now my remote server is in a lab setting (I now run a lab with multiple people, whereas before it was just me). I don't want different users to be logging in when there is a process running. I'm trying to limit people not knowing a server is in use, logging in to start a process, and disrupting (or diverting memory from) a process being run by another user.
My way around this was to setup a generic login user and password that everyone in the lab uses. Then, for that generic user, I edited the /etc/security/limits.conf file to have a maxlogins of 1 for that user. While this works in practice (no other user can log in when one is already logged in), it means I can no longer RE login.
Now I get:
local host -> tmux -> ssh into remote
remote host -> tmux -> start python process -> remote detach
remote host -> exit ssh
local host -> tmux -> ssh into remote:
Too many logins for 'lab2'.
It appears that, with the process still running, the login stays active and I am trying to 'relogin' to an ongoing login session. But since I've set the max to 1, I cannot. Does anyone have any advice for how to fix this?
Thanks!
Right now at work we have a login machine where our home area is located and all tools are run on the compute farm, to run in GUI mode I believe the job is submitted to the farm and the selected machine will run the command with the DISPLAY variable set to what was in our local environment. This seems to only work with vnc right now, is there anyway I can use SSH and use a valid DISPLAY setting?
If you establish a SSH session with X protocol tunneling, you can query the value of the DISPLAY environment variable at the remote side. For example:
client$ ssh -X server
server$ echo $DISPLAY
localhost:17.0
This value is going to be different for each SSH session.
If I'm understanding your environment correctly, you'd need to pre-establish ssh sessions to all of the node in the compute farm. Then, when the job runs on a particular compute farm node, it'd have to set the particular DISPLAY variable that goes back on the ssh session you pre-established.
Currently I have a machine setup to send files it generates via a script to a remote server for file storage, where each user has their own folder on the remote server, which they can then SFTP into to get their files.
Currently, when the machine generating the files copies them over, via SCP, it prompts for a password for the user it's sending to.
What I would like to be able to do is enable the machine to send the files to the individual user accounts without prompting for a password. I've read a few ways to do this by creating ssh keys in each user's accounts. However, due to the volume of users, I was wondering if there was a way to enable machine1 to be able to scp files to any user account on the remote file server without prompting for a password each time?
You can set up host-based authentication on the target host to accept connections from the source host. This will work for any kind of SSH access, not just SCP. If you want to limit users to just SCP, there are ways to do that. see this question for example.
Try something like:
sshpass -p scp -o StrictHostKeyChecking=no source dest
I have used it on some linux machine. Don't know if it always work (last day i tried on osX and it refused cause it will break ssh security)
BTW you have to install sshpass
I have this problem:
I have a server to which I ssh, and it has a special prompt request. The prompt is done by a ?prompt command.
It is fine with SSH, since the prompt I guess gets some input, but when I use SCP, the copy always fails.
So, I was wondering if there is maybe a flag for ssh and scp - so that interactive prompts are ignored.
(By the way, I need the prompt, so removing it isn't an option).
THANKS.
The prompt and response go into SSH stdio channels that are what scp uses to talk to the remote slave scp process, so it breaks the hand-shaking, and the transfer is aborted.
The right way to add additional prompts to SSH connections is through the keyboard-interactive authentication mechanism, probably with the help of some PAM module.
Your current approach just cripples SSH beyond simple usage patterns.