How can I reset system time to network time from the command line?
Solution 1
ntpdate deprecated
ntpdate
is deprecated, read more here: http://support.ntp.org/bin/view/Dev/DeprecatingNtpdate
For a one-shot approach
- install the ntp package with
sudo apt-get install ntp
- set a server in your
/etc/ntp.conf
- and use
sudo ntpd -q -g -x -n
for a one-time sync.
This also works for deviations up to 68 years.
Alternatively, go to "System Settings" → "Time and Date" (I'm not sure its the correct translation) to enable Network time. Note that you can't specify a server there.
Solution 2
EDIT ntpdate is now deprecated, see @Jan answer for a more secure solution.
Firt of all, you have to install the NTP server (if you don't have it yet) so
sudo apt-get install ntp
Then, check if ntp is running with
sudo service ntp status
If it's not running, you can simply type
sudo service ntp start
Then to update the time
sudo ntpdate -u time.nist.gov
time.nist.gov
is not the only one of course. Here there is a list of timeserver you can alternatively use.
source here
Related videos on Youtube
putty
Updated on September 18, 2022Comments
-
putty over 1 year
I'm having trouble defining object-level permissions for foreign-key relationships in my
ModelViewSet
. I'm not sure if it's entirely possible what I'm trying to do or if there's a better solution, but any hint in the right direction would be much appreciated. I've shortened the models and serializers for the sake of brevity.I have the following models:
class Team(models.Model): name = models.CharField(max_length=50) class CustomUser(AbstractUser): teams = models.ManyToManyField(Team) class Client(models.Model): name = models.CharField(max_length=50) owner = models.ForeignKey(Team, on_delete=models.CASCADE) class FinancialAccount(models.Model): account_name = models.CharField(max_length=50) client = models.ForeignKey(Client, on_delete=models.CASCADE)
Then I have the following serializers:
class ClientSerializer(serializers.ModelSerializer): class Meta: model = Client fields = ('name', 'owner') class FinancialAccountSerializer(serializers.ModelSerializer): owner = serializers.SerializerMethodField() class Meta: model = FinancialAccount fields = ('name', 'client', 'owner') def get_owner(self, obj): return client.owner.name
Then I'm trying to define a permission that I can use in all of my ModelViewSets. I'd like it to be somewhat dynamic as I have many more models than the ones above that are related to
Client
or even belowFinancialAccount
. The permission and viewset are as follows:class IsOwnerTeam(permissions.BasePermission): def has_object_permission(self, request, view, obj): teams = request.user.teams.values_list('name', flat=True) return obj.owner in teams class FinancialAccountViewSet(viewsets.ModelViewSet): serializer_class = FinancialAccountSerializer permission_classes = (IsOwnerTeam, ) def get_queryset(self): teams = self.request.user.teams.all() clients = Client.objects.filter(owner__in=teams) return FinancialAccount.objects.filter(account__in=accounts)
So, right now I'm receiving this error:
'FinancialAccount' object has no attribute 'owner'
, which makes sense because I don't have an owner field on theFinancialAccount
object. But, I thought if I had an owner field in the serializer (and put an owner field in each of the serializers) I could retrieve it that way. Any help would be appreciated! -
Jetson Earth over 9 yearsUsing
ntpdate
when there's a ntp server running is discouraged andntpdate
is deprecated. -
tigerjack over 9 years@Jan I didn't know that, I always used this command. Why it is deprecated? Could you provide a link?
-
Jetson Earth over 9 years
-
tigerjack over 9 years@Jan thanks for the info, I've updated my answer
-
Fabby about 6 years
-
Melebius about 6 yearsWhat is the purpose of
echo
in your script? -
Ryan Dines about 6 yearswith the backtick it just indicates a line of code as opposed to quotes, which just writes to standard out, then you suppress the output by redirecting it to /dev/null, idk, i think maybe you can leave them out on ubuntu? I know for Centos/RHEL I needed them