Easiest way to do a remote sudo

Easiest way to do a remote sudo

Let’s see the easiest way to do a remote sudo:

Usually when a sudo command is executed in a remote server, an error is receive telling us that a remote sudo in not possible, even if the user have permissions for the command we want to use.

easiest way to do a remote sudo 01

This is because sudo, by default, requires a tty to be executed, making not possible to execute it.

CollectNode captures the sudo commands and processes them in a way that this requirement is no longer a problem.

easiest way to do a remote sudo 02

With the command configure we can now configure the password to use if the sudo execution requires a password in the remote servers.  If the sudo password is not configured, CollectNode will use the password of the user used to connect to the remote servers.

Now execute remote sudo is easiest than ever  🙂

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

Ctrl+Z or What to do when Ctrl+C doesn’t work

Ctrl+Z or What to do when Ctrl+C doesn’t work

When a process launched become hanged, the most useful option to kill it is to press Ctrl+C, but what to do when Ctrl+C doesn’t work?
In this cases it is very useful to use Ctrl+Z. While Ctrl+C tries to kill the process with the signal SIGINT, Ctrl+Z sends the process to the background, releasing the terminal that was inoperative because the process, and giving us the control again.
Let’s see how to do it using an example. (At the end of the post you can find a video explaining all the process)

To simulate a hang process I am going to launch the python script ignoring_CtrlC.py, that intercept the Ctrl+C signal, making a forever process.

Executing ignoring_CtrlC.py

When I execute the script, and press Ctrl+C this is what happen

CtrlC doesnt work 01

Ctrl+C is not working, instead is displaying a message.

Let’s press now Ctrl+Z and see what happen now

CtrlC doesnt work 02

CtrlC doesnt work 03
The script is now stopped! but still alive at background, it is time to kill it!!

Killing a background process

To kill a background process, we use the command kill, but instead of use the PID of the process, we have to use the background ID, that is indicated between [].

CtrlC doesnt work 04

CtrlC doesnt work 05

Job done!!
The process is killed and the terminal control recovered 🙂

Video explaining all the process

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

Video: Understanding CollectNode output

Video: Understanding CollectNode output

In this video we can check the CollectNode output. How CollectNode executes a simple command, and gets the report, which is explained. The command to execute is:

The getent command displays entries from databases supported by the Name Service Switch libraries

We want to know if the account apache is available at the servers involved.

The hosts file used has 7 servers, one server is duplicated and other that doesn’t exist, in order to see the behaviour of CollectNode in these cases.

Understanding CollectNode output

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

video: How to get list of servers sorted by OS

video: How to get list of servers sorted by OS

In this video we will see how to get a list of servers sorted by OS, displaying the operating system for each one, CollectNode gets the servers from a file, then analyze them and finally displays the report.

Enjoy!

 

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

Change user password remotely

Change user password remotely

It is easy to change the password for a local user, just type:

and follow the instructions.
But, when we have to change password remotely, things became more complicated. We can make login in each server and change the password manually as explain before,  or change the password remotely using ssh as connection mode, saving time and effort, that we can spend in other tasks. Let’s see how to do it.

root user

If we are root, the solution can be very simple, we will use the command passwd with the option --stdin

–stdin:

This option is used to indicate that passwd should read the  new  password
from standard input, which can be a pipe.

So the command to change the password of user1 to newPassword would be like this:

If the command passwd doesn’t have the option --stdin, because the version,  we can use the following method for non root users.

Non root user

If we are not root, we cannot use --stdin option from passwd, so we have to modify the command a little.

  • non root user, only can change their own password,
  • they have to type the current password
  • they have to type the new password twice
  • accomplish the password policies, that root can ignore.

 

So to accomplish this requirements, we can use the option -e from echo command, that allow us to use the new line code \n , so we can pass to command passwd the input expected without the --stdin option.

-e:

 enable interpretation of backslash escapes

So finally the command to change the password of user1 to newPassword would be like this:

Put into practice

Let’s see an example where we have to change the password for user1 to oth3r0n3 in five servers, we will use CollectNode to execute the command in all servers quickly and get the command results for each server.

first of all we add the servers name to the file hosts.txt

And now we will use the command for root user:
changing user password remotely

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

Pin It on Pinterest