Linux Programmer | RHCE | RHCSA

Search This Blog

Thursday, 27 January 2022

Execute programs with sudo privilleges with non-root users

Sometimes we don't want normal users to provide sudo rights. but we want to run some scripts which can only run with the sudo.

in that case we can set user rights that will run only specific script with sudo privilleges.

You can perform this by three ways.

Method 1:

 
Create file (vim /etc/sudoers.d/iosys) and add below lines in created file.
 

username ALL=NOPASSWD:/command/to/execute
username ALL=NOPASSWD:/command/to/execute 

Note: Change username accordingly.

Method 2: 


Open below configuration file, and made provided changes into it.

nano /etc/sudoers

Edit it with below lines,


# User privilege specification
 

root    ALL=(ALL:ALL) ALL

ALL ALL =(root) NOPASSWD:/command/to/execute
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%sudo   ALL=NOPASSWD:/command/to/execute 




Allow SSH for specific IP without using IPTABLES.

With using below steps you can block and Allow specific IPs to take SSH without using iptables and Firewall.

Open below file,

cat /etc/hosts.allow

sshd: 192.168.0.13 : allow
sshd: ALL : deny

This will allow SSH for 192.168.0.13 IP only.

Wednesday, 24 November 2021

Preserve bash history

 # Maximum number of history lines in memory

export HISTSIZE=50000

# Maximum number of history lines on disk

export HISTFILESIZE=50000
 
# Ignore duplicate lines

export HISTCONTROL=ignoredups:erasedups

# When the shell exits, append to the history file instead of overwriting it

shopt -s histappend

# After each command, append to the history file and reread it

export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'n'}history -a; history -c; history -r"
 
 
# Linux command history with date and time.

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile

Or set it permenant, add below entry into .bashrc

export HISTTIMEFORMAT="%d/%m/%y %T "

Thursday, 18 November 2021

Execute custom script as command.

Create bash script, 

Create file: script.sh

#!/bin/bash 

date echo "testing" 

 

 Apply executable permission.

# chmod 0777 script.sh
 

Move script to /usr/local/bin/

# mv script.sh /usr/local/bin/

 

Now you can execute script from anywhere.

# cd /home/

# script.sh

output:

Thu Nov 18 11:05:41 IST 2021

testing


M3 Button not working in Wayland

Mouse M3 button not working in wayland - ubuntu 26.04 1. Check your desktop Run: echo $XDG_SESSION_TYPE echo $XDG_CURRENT_DESKTOP 2. If...