LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   NTP - I want use like common user (https://www.linuxquestions.org/questions/slackware-14/ntp-i-want-use-like-common-user-4175736517/)

inukaze 04-28-2024 04:58 PM

NTP - I want use like common user
 
Ok i had wrote this script some time ago

Code:

cat /usr/bin/SincronizarHora.geb
#!/usr/bin/env bash

echo '
Autor ----------------> Inukaze ( Venezuela )
Sitio ----------------> https://goo.gl/ij6WqW
Correo-E -------------> bloginukaze@gmail.com
Licencia -------------> GPL 2

******* Inicio : Acerca de este Guión ********

  Yo intento escribir guiones compatibles con
  Sistemas operativos Unix & POSIX , y otros
  Sistemas operativos que soporten bash

  Este archivo es un guion sencillo para
  Sincronizar la hora utilizando
  « ntpdate » (asi que debe estar instalado)

******** Fin : Acerca de este Guión **********'
sleep 3

#Determinar en que directorio estoy :
GUION=$(readlink -f "$0")
RUTA=$(dirname "$GUION")
ntpdate=$(whereis -B "/usr/sbin" "/usr/local/sbin" "/sbin" "/usr/bin" "/usr/local/bin" "/bin" -b ntpdate | grep -i "ntpdate" | cut -d " " -f02 | cut -c11-20)
service=$(whereis -B "/usr/sbin" "/usr/local/sbin" "/sbin" "/usr/bin" "/usr/local/bin" "/bin" -b service | grep -i "service" | cut -d " " -f02 | cut -c11-20)
rcntpd="/etc/rc.d/rc.ntpd"

if [ -z "$ntpdate" ]; then
        echo
        echo "ntpdate no esta instalado en tu sistema operativo GNU"
        echo "Por favor, instale primero « ntpdate »"
        echo
        exit 0
fi

#Slackware(64) :
if [ -d "/etc/rc.d" ];then
        if [ -f "$rcntpd" ]; then
                chmod +x "$rcntpd"
                "$rcntpd" "stop"
                #ntpdate -u 0.south-america.pool.ntp.org
                ntpdate -u time.nist.gov
                hwclock -w
                "$rcntpd" "start"
        fi
fi

#Debians :
if [ -z "$service" ]; then
        echo ""
else
        sudo service ntpd stop
        sudo su -c "rm -rf /etc/localtime" root
        sudo su -c "ln -s /usr/share/zoneinfo/America/Caracas /etc/localtime" root
        echo 'TZ='America/Caracas'; export TZ' >> "$HOME/.profile" ; source "$HOME/.profile"
        sudo update-locale LC_TIME=es_ES.UTF-8
        #ES#sudo su -c "cp -rf $PWD/usr/share/i18n/locales/es_ES /usr/share/i18n/locales/es_ES" root
        #ES#sudo su -c "cp -rf $PWD/usr/share/i18n/locales/es_ES@euro /usr/share/i18n/locales/es_ES@euro" root
        #ES#sudo su -c "cp -rf $PWD/usr/share/i18n/locales/es_VE /usr/share/i18n/locales/es_VE" root
        LANG="es_ES.UTF-8" ; export LANG="$LANG"
        LANGUAGE="es_ES.UTF-8" ; export LANGUAGE='"'"$LANGUAGE"'"'
        LC_ALL="es_ES.UTF-8" ; export LC_ALL="$LC_ALL"
#      ntpdate -u 0.south-america.pool.ntp.org ; hwclock -w
        ntpdate -u time.nist.gov ; hwclock -w
        sudo service ntpd start
fi

exit 0

right now i prefer use " Network Manager " for manual configuration IP inside the KDE Plasma Desktop [ Grafical Session ].

if i try ran commands like normal user :

Code:

su -c "gpasswd -a inukaze ntp ; gpasswd -a inukaze ntpd" root
Quote:

Contraseña:
Añadiendo al usuario inukaze al grupo ntp
gpasswd: el grupo «ntpd» no existe en /etc/group
Code:

rcntpd stop
Quote:

Stopping NTP daemon.../etc/rc.d/rc.ntpd: línea 15: kill: (1022) - Operación no permitida
rm: no se puede borrar '/run/ntpd.pid': Permiso denegado
if my user is part of ntp group, why not had permission to delete the file '/run/ntpd.pid' ?

Code:

ntpdate -u time.nist.gov
Quote:

28 Apr 17:51:02 ntpdate[3406]: step-systime: Operation not permitted

Code:

$rcntpd start
Quote:

Starting NTP daemon: /usr/sbin/ntpd -g -u ntp:ntp28 Apr 17:54:45 ntpd[3943]: must be run as root, not uid 1000
Code:

hwclock -w
Quote:

bash: hwclock: orden no encontrada
The hwclock command just can be use by the root ?

Ok why for just sync clock hour i need root permission ?


Which things i should edit for all users inside ntp group can use commands ; ntpd, hwclock

stop/start/restart/status ntp, ntpd, services.
can delete and create the file " /run/ntpd.pid "

mrsam 04-28-2024 05:52 PM

/run is owned by root, so only root can remove /run/ntpd.pid. In Linux you must have write permissions on the directory in order to have the permission to remove a file from it, the permissions or the ownership of the file is immaterial.

But there are more fundamental issues here.

ntp uses port 123. For all practical matters: Linux allows only root-owned processes to bind to ports below 1024 (the actual permissions are based on Linux-specific "capabilities", but this gets too deep in the weeds here).

TLDR: you need to be root in order to start or stop ntpd. Non-root permissions won't be enough.

HQuest 04-29-2024 01:11 PM

Add your user to the sudoers file, allow it to use ntpdate, and then use "sudo ntpdate -u time.nist.gov" instead.

Something like this should work (and not even ask for your inukaze account password):
# more /etc/sudoers.d/ntpdate
inukaze your-hostname-here = NOPASSWD: /usr/bin/ntpdate

For more information,
man sudo
man sudoers

Also, ntpd is a service you start once and let it do its thing; no need to keep restarting it.

inukaze 04-29-2024 03:16 PM

Quote:

Originally Posted by HQuest (Post 6498899)
Add your user to the sudoers file, allow it to use ntpdate, and then use "sudo ntpdate -u time.nist.gov" instead.

Something like this should work (and not even ask for your inukaze account password):
# more /etc/sudoers.d/ntpdate
inukaze your-hostname-here = NOPASSWD: /usr/bin/ntpdate

For more information,
man sudo
man sudoers

Also, ntpd is a service you start once and let it do its thing; no need to keep restarting it.

Yesterday i had do that, but my on my sudoers file, becuase when i make a custom file inside /etc/sudoers.d/ntp , the thing does not work i hope, but after i move the line to sudoers and using the command
Code:

visudo -c
to check the syntax i and notice i wrote bad in multiples times, things like the commands not should be write like "/sbin/hwclock", because does not work.

the line inside my sudoers file is :

Code:

%ntp  Slack64 = NOPASSWD: /usr/bin/ntpdate, /usr/sbin/ntpdate, /usr/sbin/ntpd, /usr/sbin/ntpq, /sbin/hwclock
well the thing is when i try to run the command like my user :
Code:

ntpdate -u time.nist.gov
Quote:

29 Apr 16:13:04 ntpdate[3331]: Can't adjust the time of day: Operation not permitted
Why the error msg change ? , some hours ago was "step-systime : Operation not permitted"
Quote:

29 Apr 15:21:27 ntpdate[2665]: step-systime: Operation not permitted
after i do
Code:

su -c "ln -sf /sbin/hwclock /usr/bin/hwclock" root
after i edit my /etc/rc.d/rc.local and add the follow lines between the first lines :
Code:

# Sincronizar Hora durante el arranque :
if [ -x /etc/rc.d/rc.ntpd ]; then
        /etc/rc.d/rc.ntpd stop
        /usr/sbin/ntpd/ntpd -gq > /dev/null 2>&1
        hwclock -w
        /etc/rc.d/rc.ntpd start
fi


vondyke 04-29-2024 08:55 PM

> well the thing is when i try to run the command like my user :
>
> ntpdate -u time.nist.gov

Did you try `sudo ntpdate -u time.nist.gov`? Adding the custom sudoers file is the first part of the puzzle, but you still need to use `sudo` when running the command

inukaze 04-30-2024 04:04 PM

Quote:

Originally Posted by vondyke (Post 6498950)
> well the thing is when i try to run the command like my user :
>
> ntpdate -u time.nist.gov

Did you try `sudo ntpdate -u time.nist.gov`? Adding the custom sudoers file is the first part of the puzzle, but you still need to use `sudo` when running the command

Code:

sudo ntpdate -u time.nist.gov ; sudo hwclock -w
Quote:

30 Apr 17:04:39 ntpdate[22694]: adjust time server 132.163.97.3 offset -0.001452 sec

vondyke 04-30-2024 11:44 PM

Quote:

Originally Posted by inukaze (Post 6499128)
Code:

sudo ntpdate -u time.nist.gov ; sudo hwclock -w

That's good, right? Is this what you wanted to accomplish?

inukaze 05-02-2024 12:27 PM

Quote:

Originally Posted by vondyke (Post 6499193)
That's good, right? Is this what you wanted to accomplish?

Yes. Sorry i forgot mark as solved.


All times are GMT -5. The time now is 09:34 AM.