K
K
kovalr2016-12-23 13:47:20
bash
kovalr, 2016-12-23 13:47:20

How to execute a command as root via ssh in Linux Mint in a bash script?

I have about 40 Linux Mint machines. It is necessary to change the config for all ssh
Script example

#!/bin/bash
su user1 << BASH
sudo su root << BASH

cd /etc/ssh/sshd_config 
wget https://localhost/file -O sshd_config

exit 0

I run
ssh [email protected] 'bash -s' < run.sh
In response
su: must be run from a terminal
, root is disabled via ssh.
You can login as root in a terminal with either sudo -i or sudo su root.
user1 in the sudo group
How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2016-12-23
@CityCat4

Mass updating of configs is usually done by means of remote deployment - Chef, Puppet. Do it via ssh, and even when logging in as root... If you really need it this way, then I would do it a little differently - I created a user on each server, a regular user, set up key authentication, gave him the right to execute some script... The mechanics turns out to be quite complicated, Puppet will probably be easier to set up :)

A
Alexander, 2016-12-23
@asand3r

All in all, I don't know.
But so, suddenly a thought will help - I would solve the problem with updating configs with tools like Puppet and Ansible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question