3

I'm just starting with a clean install of Ubuntu Server 12.04. I've run:

$ sudo apt-get update
$ sudo apt-get upgrade

I've added the following to /etc/hosts:

127.0.0.1       (hostname)

The file previously contained:

127.0.0.1       localhost
127.0.1.1       (hostname).hsd1.(state).(ISP).net        (hostname)

# The following....
...

I was only able to save edits to that file once I became root [by: su -l]. I'm able to ssh with username@ip. However, I'd like to be able to ssh with @hostname

What am I missing?

My goal is to set up a simple LAMP Web Server for PHP website testing.

1

You don't need to include the @hostname to ssh to another host. That's only required if you'd like to ssh as some other user than the one you're currently logged into, on your local machine.

Example

$ whoami
saml

$ hostname
grinchy

If I just ssh <remotehost> to some other computer I'll be implicitly trying to login to <remotehost> as user saml.

Perhaps this user is or isn't also a user on <remotehost>. You have to know this ahead of time. So rather than rely on a username being the same on multiple systems, people typically explicitly include this info in their connection commands when using ssh.

$ ssh someuser@remotehost

If you're positive the local user is the same across systems then you can use this:

$ ssh remotehost

.ssh/config file

If you find you have lots of different usernames and remote hosts that you have to login to you can make use of ssh's config file. This file is typically in your $HOME directory. This file needs to be manually created so it may not even exist. Here's a sample file:

# web server
Host webby webby.mydom.com
    User someuser
    Hostname webby.mydom.com

With this stanza in your config file you can now just ssh to the host webby and it will automatically use the username someuser by default.

$ ssh webby

You're still able to override this, for example:

$ ssh someotheruser@webby

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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