LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-28-2024, 04:58 PM   #1
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Rep: Reputation: 26
Question 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 "
 
Old 04-28-2024, 05:52 PM   #2
mrsam
LQ Newbie
 
Registered: Jan 2024
Distribution: Fedora, Ubuntu, Slackware
Posts: 4

Rep: Reputation: 2
/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.
 
1 members found this post helpful.
Old 04-29-2024, 01:11 PM   #3
HQuest
Member
 
Registered: Jan 2018
Location: 2001:470:c2d0::/56
Distribution: Anything I can interface with
Posts: 92

Rep: Reputation: Disabled
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.

Last edited by HQuest; 04-29-2024 at 01:19 PM.
 
Old 04-29-2024, 03:16 PM   #4
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by HQuest View Post
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
 
Old 04-29-2024, 08:55 PM   #5
vondyke
LQ Newbie
 
Registered: Jul 2022
Posts: 6

Rep: Reputation: 4
> 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
 
1 members found this post helpful.
Old 04-30-2024, 04:04 PM   #6
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by vondyke View Post
> 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

Last edited by inukaze; 04-30-2024 at 04:05 PM.
 
Old 04-30-2024, 11:44 PM   #7
vondyke
LQ Newbie
 
Registered: Jul 2022
Posts: 6

Rep: Reputation: 4
Quote:
Originally Posted by inukaze View Post
Code:
sudo ntpdate -u time.nist.gov ; sudo hwclock -w
That's good, right? Is this what you wanted to accomplish?
 
1 members found this post helpful.
Old 05-02-2024, 12:27 PM   #8
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by vondyke View Post
That's good, right? Is this what you wanted to accomplish?
Yes. Sorry i forgot mark as solved.
 
  


Reply

Tags
ntp, slackware



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ntp server keeps on changing time-local ntp server Gil@LQ Linux - Newbie 3 01-23-2013 09:33 AM
ntp drift file in /etc/ntp instead of /var/lib/ntp - suggestion for a patch in Slack niels.horn Slackware 16 05-07-2009 07:35 PM
NTP's ntp.conf pxumsgdxpcvjm Linux - Server 2 08-30-2007 09:34 PM
NTP cannot work with timeserver, NTP-d can jerryvapps Linux - Networking 0 08-04-2004 02:04 PM
NTP cannot use server, NTP -d can jerryvapps Linux - Newbie 0 07-28-2004 02:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration