Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a machine that I can only access using SSH.

I was messing with the hostnames, and now it says:

ssh: unable to resolve hostname

I know how to fix it in /etc/hosts.

Problem is, I need sudo to fix them because my normal account doesn't have permissions.

What's the best way to fix the hosts?

share|improve this question
    
Instead of editing /etc/hosts, maybe unix.stackexchange.com/questions/10438/… would help? –  jamesdlin Apr 13 at 8:54

2 Answers 2

up vote 2 down vote accepted

You don't need sudo to fix that, try pkexec,

pkexec nano /etc/hosts
pkexec nano /etc/hostname

After running pkexec nano /etc/hosts, add your new hostname in the line that starts with 127.0.1.1 like below,

127.0.0.1   localhost
127.0.1.1   your-hostname

And also don't forget to add your hostname inside /etc/hostname file after running pkexec nano /etc/hostname command,

your-hostname

Restart your PC. Now it works.

share|improve this answer
    
I'm a little confused. What exactly does pkexec do? Also when I ran it on the hosts file, it showed up with a blank doc. When I saved, did I overwrite what was there? –  evamvid Apr 13 at 4:16
    
pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root. –  Avinash Raj Apr 13 at 4:18
    
So it's like a backup/fake sudo? Awesome! –  evamvid Apr 13 at 4:19
    
And, I'm not sure why it showed blank, but it seems to have worked -- now I'm trying to fix the actual hosts problem –  evamvid Apr 13 at 4:19
    
Yes, try to fix that. You said "I know how to fix it in /etc/hosts and /etc/hostname" –  Avinash Raj Apr 13 at 4:20

You need sudo or root privileges to edit the /etc/hosts file in your local host. If you don't, there is no way of editing this file.

Then you must add an entry to /etc/hosts so that your local host can resolve properly the hostname of the remote host.

This is the format of the lines in /etc/hosts

127.0.0.1   localhost.localdomain   localhost
10.10.2.9   remotehost.labs         remotehost
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.