2

I changed my hostname on my Ubuntu (12.04) computer but my CentOS computer still connects to it using the old hostname. How can I make it so that I can type:

ssh new_hostname

instead of :

ssh old_hostname

and it will connect to my computer still?

I edited the /etc/hostname file and the /etc/hosts file and I also restarted my computer and in the terminal it shows my hostname, but ssh still only connects with the old hostname.

3
  • Did you only change the hostname in /etc/hostname?
    – Wilf
    Jul 13, 2015 at 20:29
  • Edited the question. Jul 13, 2015 at 20:33
  • Check ~/.ssh/config, you can have aliases defined there.
    – Rmano
    Jul 13, 2015 at 20:36

1 Answer 1

0

Make sure you changed the entry in /etc/hosts - e.g. for serverlaptop:

127.0.0.1 localhost
127.0.1.1 serverlaptop

...

Otherwise, you may need to edit the ~/.ssh/config (perhaps even /etc/ssh/ssh_config) file on the computer you are trying access the SSH server from to use the new hostname as the short name - e.g.

Host serverlaptop
   User wilf
   HostName 192.168.1.48

For instance the above entry in ~/.ssh/config makes ssh serverlaptop act as a alias for ssh [email protected] - if one does not exist already you can create it (replacing serverlaptop with the hostname, and wilf with your username) so ssh HOSTNAME will work.

5
  • I don't have a ~/.ssh/config file on my computer. I only have a known_hosts file in the .ssh folder. Jul 13, 2015 at 20:40
  • Do I make tabs next to User and Hostname? Jul 13, 2015 at 21:49
  • @TakamaruTaihou, just create the .ssh/config file.
    – Daniel
    Jul 13, 2015 at 21:51
  • +1 It worked, but how would I make it so I don't need to do it for other computers that may also connect, or do I have to do it for all computers that I want to connect to my Ubuntu? Jul 13, 2015 at 21:55
  • I suppose a method would be to temporarily remove ~/.ssh/config fix, and then run ssh -vvv OLD_HOSTNAME to see how it resolves the hostname. If you want to post any output you can edit it into your question.
    – Wilf
    Jul 13, 2015 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .