5

I see that users including myself at work do ssh to 127.0.0.1. In my case I do it as a different user and to a non-standard port as part of reaching my Linux work environment (the hosting).

I wonder why I do that?

The command I use is ssh username@127.0.0.1 -p xxxxx where xxxxx is the port number (not port 22 but something completely different).

The procedure is part of me inheriting old Linux installations at work. What would be the difference between ssh user@127.0.0.1 and just su user ?

2
  • 6
    Since we have absolutely no data about how the SSH service at xxxxx is set up, this question is essentially unanswerable. For all we know, there might be a container running with SSH forwarded from xxxxx, and the container environment might be entirely different.
    – muru
    Jul 12, 2017 at 10:50
  • 1
    The why could be anything, what the answers says or muru or something else. If we are able to answer it, we would need more information about the service running in the localhost:port, which most likely will take you to your sysadmin, which can tell you exactly why it is set up like that....
    – Braiam
    Jul 12, 2017 at 12:17

3 Answers 3

14

If you use ssh user@127.0.0.1, you are effectively logging in again, so you get the standard login environment for that user. su user will just change user.

A better comparison would be with su - user, which does set the environment. In that case, there seems to be little difference unless you are doing something special.

I wonder if the people who are using ssh are just using inherited company lore because no-one knew about - with su!

2
  • From an X session, could there be differences? I.E. does 'su - user' allow the resulting shell to use the current X session?
    – TREE
    Jul 12, 2017 at 13:18
  • If you're in a command line window (e.g. xterm), yes it does.
    – Bob Eager
    Jul 12, 2017 at 13:22
4

There wouldn't be a lot of difference unless they configured some special environment for the ssh connection.

You could look it up either in /home/user/.ssh/ssh_config, /etc/ssh/sshd_config or /etc/sshd_config.

1
3

Based on the information in the question, there is no reason to assume that the SSH connection ends up on the local machine at all.

I've sometimes seen a particular port being forwarded from localhost to a ssh server on a remote host. Then ssh user@localhost -p 12345 becomes equivalent to ssh user@remote.example.com, with the obvious differences from local su.

The reason for such a setup is usually that this way the users do not have to remember or know about remote.example.com, and can in fact be firewalled so that they cannot even access it directly. This also allows the admins to transparently change how the actual connection is routed.

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