5

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?

mavillan
  • 3,097
evamvid
  • 688
  • Instead of editing /etc/hosts, maybe http://unix.stackexchange.com/questions/10438/can-i-create-a-user-specific-hosts-file-to-complement-etc-hosts would help? – jamesdlin Apr 13 '14 at 08:54

2 Answers2

4

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
mavillan
  • 3,097
2

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.

Avinash Raj
  • 3,703