LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2016, 03:00 PM   #1
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Rep: Reputation: 19
Exclamation systemd hostnamectl changes hostname without sudo


If I want to change the hostname on one of my Xubuntu 16.04.1 installations I usually edit /etc/hostname and /etc/hosts, which requires doing the usual 'sudo' to access the files in write mode as both have '-rw-r--r-' permissions.

I recently saw reference to the systemd command 'hostnamectl' which changes the environment variable and edits /etc/hostname at the same time, but I have found that it does not require 'sudo'. I can just enter 'hostnamectl set-hostname <whatever>' in a terminal and the string in /etc/hostname has been changed, without ever being asked for a password.

Is hostnamectl supposed to do that? It means anyone can change the hostname without root access. Surely this should require an admin password to do that.
 
Old 10-26-2016, 04:30 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,836

Rep: Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370
When I see this I assume that the user has been granted some higher level permission. You'd have to check on that to be sure. I get the feeling that you are not changing the traditional host name.

Look at this for some tips.
https://www.freedesktop.org/software...stnamectl.html

http://www.cyberciti.biz/faq/rhel-re...tname-command/

Last edited by jefro; 10-26-2016 at 04:32 PM.
 
Old 10-26-2016, 05:49 PM   #3
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by jefro View Post
When I see this I assume that the user has been granted some higher level permission. You'd have to check on that to be sure. I get the feeling that you are not changing the traditional host name.
I thought the same thing, that somehow I had messed up the permissions, but I can't find anything to support that premise. Just to be sure, though, I performed a fresh unmodified install of Xubuntu 16.04.1 onto an old hard drive, and the same situation occurred on first boot - no password is required to change the hostname through hostnamectl. As to the 'traditional host name', hostnamectl is changing the text in /etc/hostname, and I thought that was the reference for the systems's hostname.

Code:
phil@Xubuntu-Development:~$ hostname
Xubuntu-Development
phil@Xubuntu-Development:~$ cat /etc/hostname
Xubuntu-Development
phil@Xubuntu-Development:~$ hostnamectl set-hostname Xubuntu-Whatever
phil@Xubuntu-Development:~$ hostname
Xubuntu-Whatever
phil@Xubuntu-Development:~$ cat /etc/hostname
Xubuntu-Whatever
phil@Xubuntu-Development:~$ hostnamectl set-hostname Xubuntu-Development
phil@Xubuntu-Development:~$ hostname
Xubuntu-Development
phil@Xubuntu-Development:~$ cat /etc/hostname
Xubuntu-Development
I also tried one of my Linux Mint 18 Mate installations on a different computer, and again hostnamectl does not require a password to rewrite /etc/hostname. At the moment I'm inclined to think this is a bug in either systemd or Ubuntu's implementation of systemd.

Last edited by genogebot; 10-26-2016 at 06:03 PM. Reason: More information
 
Old 10-26-2016, 06:03 PM   #4
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
Wow! "If it's too good|bad to be true, it probably isn't [true]"! Maybe post output of:

ls -l `which hostnamectl`
sum /usr/bin/hostnamectl
dpkg -V systemd
 
Old 10-26-2016, 06:11 PM   #5
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by Jjanel View Post
Wow! "If it's too good|bad to be true, it probably isn't [true]"! Maybe post output of:

ls -l `which hostnamectl`
sum /usr/bin/hostnamectl
dpkg -V systemd
Speak, and it shall be done :

Code:
$ ls -l `which hostnamectl`
-rwxr-xr-x 1 root root 294096 Oct  5 10:13 /usr/bin/hostnamectl
$ sum /usr/bin/hostnamectl
29693   288
$ dpkg -V systemd
??5?????? c /etc/systemd/system.conf
??5?????? c /etc/systemd/timesyncd.conf
??5?????? c /etc/systemd/journald.conf
Code:
$ debsums systemd | grep hostnamectl
/usr/bin/hostnamectl                                                          OK
/usr/share/bash-completion/completions/hostnamectl                            OK
/usr/share/man/man1/hostnamectl.1.gz                                          OK
/usr/share/zsh/vendor-completions/_hostnamectl                                OK

Last edited by genogebot; 10-26-2016 at 06:37 PM.
 
Old 10-26-2016, 06:35 PM   #6
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
file /usr/bin/hostnamectl
will probably say 64bit; mine is 32bit, but it's probably ok [because]
I tried [strace then] ltrace -S -f -o xx [sudo] hostnamectl set-hostname whatever
*BUT* it 'talks' over socket to Dbus, so I have no idea how to trace the systemd 'MONSTER' & gave up.
No idea on the dpkg -V 'errors[?]' ... Over to next LQ 'hacker' "Crash Systemd in One Line as Any User"

Last edited by Jjanel; 10-26-2016 at 06:44 PM.
 
Old 10-26-2016, 06:39 PM   #7
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by Jjanel View Post
file /usr/bin/hostnamectl
will probably say 64bit; mine is 32bit, but it's probably ok [because]
I tried [strace then] ltrace -S -f -o xx [sudo] hostnamectl set-hostname whatever
*BUT* it 'talks' over socket to Dbus, so I have no idea how to trace the systemd 'MONSTER' & gave up.
No idea on the dpkg -V 'errors[?]' ... Over to next LQ 'hacker'
Yeah, I tried tracing the calls when I was first investigating this, and I hit the same wall. I was trying to see at what point /etc/hostname was modified, but I couldn't find any reference to that file in the output, so I just moved on.
 
Old 10-26-2016, 06:55 PM   #8
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
It is true! I have a little domesticated Mint in a VM to support friends who run *buntus. User definitely can change the hostname without elevated rights.
 
Old 10-26-2016, 07:12 PM   #9
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,836

Rep: Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370Reputation: 3370
Find the command and change file based permissions. ???

Another systemd bug. ??

Last edited by jefro; 10-26-2016 at 07:16 PM.
 
Old 10-26-2016, 08:01 PM   #10
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Ok, on the (possibly incorrect) assumption that this is a bug in Ubuntu, I filed a bug report at https://bugs.launchpad.net/ubuntu/+s...d/+bug/1637030. The bug reporting system made it 'private' because it is security-related. Presumably that will change.
 
Old 10-26-2016, 08:04 PM   #11
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
I have RPi here running Raspbian (Debian) for Agocontrol. I tried to change the hostname as unprivileged user and was asked to authenticate.
 
Old 10-26-2016, 08:06 PM   #12
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by Emerson View Post
I have RPi here running Raspbian (Debian) for Agocontrol. I tried to change the hostname as unprivileged user and was asked to authenticate.
Thanks, that reinforces the view that this is an Ubuntu systemd implementation bug.
 
Old 10-26-2016, 08:11 PM   #13
Timothy Miller
Moderator
 
Registered: Feb 2003
Location: Arizona, USA
Distribution: Debian, EndeavourOS
Posts: 3,661
Blog Entries: 7

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Quote:
Originally Posted by genogebot View Post
Thanks, that reinforces the view that this is an Ubuntu systemd implementation bug.
Yup, I can confirm on my Debian laptop that it asks for authentication when trying it as an unprivileged user.

edit: also tried on one of my Arch linux machines, and was prompted when attempting as a non-privileged user.

Last edited by Timothy Miller; 10-26-2016 at 08:30 PM.
 
Old 10-26-2016, 11:38 PM   #14
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by Jjanel View Post
it 'talks' over socket to Dbus, so I have no idea how to trace the systemd 'MONSTER'
I followed the info at https://wiki.ubuntu.com/DebuggingDBus - specifically the part about 'How to monitor the system bus'. I did the modification on the old hard drive installation of Xubuntu 16.04.1 and did
Code:
sudo dbus-monitor --system > dbus-mon.txt
then in another terminal did
Code:
hostnamectl set-hostname Xubuntu-Bad
This produced a 60kB file containing a lot of method call debug text such as:
Code:
method call time=1477537351.012853 sender=:1.66 -> destination=org.freedesktop.hostname1 serial=4 path=/org/freedesktop/hostname1; interface=org.freedesktop.hostname1; member=SetHostname
   string "Xubuntu-Bad"
   boolean true
So if you ever want to trace dbus, maybe that's the way to do it.

Was it helpful? Not in the least Not yet, anyway. I'm still digging through it.

I did see (at https://www.freedesktop.org/wiki/Software/systemd/dbus/ this:
Quote:
Security

Read access is generally granted to all clients, but changes may only be made by privileged clients. PolicyKit is not used by this service, and access controlled exclusively via the D-Bus policy enforcement.
So perhaps the problem lies in Ubuntu's dbus security configuration.
Attached Files
File Type: txt dbus-mon.txt (62.6 KB, 22 views)
 
Old 12-16-2016, 04:23 AM   #15
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
Your bug got 'resolved'[?]. Is your polkit hostname1 same as github? (sudo[?])

Last edited by Jjanel; 12-16-2016 at 04:38 AM.
 
  


Reply

Tags
hostname change, permitted, sudo, systemd


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
hostnamectl, localectl, and most other *ctl commands do not work. Systemd is running. xwjitftu Arch 1 11-22-2012 05:44 AM
sudo fails - "sudo: can't get hostname: Success" fantasygoat Linux - Server 3 10-01-2009 02:59 PM
sudo fails due to hostname edgjerp Ubuntu 6 05-05-2008 12:51 AM
Ubuntu 6.06 - changed /etc/hostname and now sudo is not working. morrolan Linux - Newbie 3 06-01-2006 04:10 PM
changed hostname: now sudo and xhost gone goofy iggymac Linux - Networking 2 06-13-2002 10:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:03 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