SSH to server without including username in URL on Linux/Unix/Mac
Solution 1
In ~/.ssh/config
:
host shortname
hostname long.name.tld
user your-username
Then you can type ssh shortname
and it will login as your-username
Solution 2
You would have to write a wrapper script for ssh.
#!/bin/bash HOST=$1 read -p "user: " USER ssh -l $USER $HOST
then use that wrapper script i.e ./ssh-wrapper hostname
I see no point in this but thats what you'd have to do.
Related videos on Youtube
TheRealKingK
Updated on September 18, 2022Comments
-
TheRealKingK over 1 year
I am trying to ssh into my server from the command-line without including the username in the url. I do not want it to send any username, as it currently takes the active account and sends that as user.
ex: ssh server.com -> (doesn't send default username)
instead of [email protected]
I would want to input username directly into the server, just like it is done using putty on windows.
As birryree said:
Oh I get it...he wants to be prompted for a username, rather than having to provide one when connecting - but I don't really see the utility in such a thing. – birryree Sep 8 at 17:41-
Tom over 12 years
I would want to input username directly into the server
- what? Putty just saves a configuration so it knows what user to use, if you configure it that way. -
Admin over 12 yearsYup, SSH is done on a user account basis as far as I know so if you connect without a user how can the server authenticate you?
-
Tom over 12 yearsOh I get it...he wants to be prompted for a username, rather than having to provide one when connecting - but I don't really see the utility in such a thing.
-
Admin over 12 yearsthat can't be done from the server side.
-
Admin over 12 yearsIs there a particular reason you want to do this other than personal preference? i.e., you want to hide the username in the process list or something like that.
-
Ernest over 12 yearsFWIW, PuTTY doesn't really let the server prompt you for a username -- it's done locally, just in the terminal window where the server's output would go.
-
akira over 12 years@TheRealKingK: why do you want to enter the username instead of 'sending' it?
-
TheRealKingK over 12 years@evil otto: Yes I would want to hide the username from the history of the local machine
-
TheRealKingK over 12 years@birryree That you for clarifying my question, that is exactly what I am trying to do On putty on windows this behavior occurs, I was trying to find the linux equivalent
-
Dessa Simpson about 9 years@TheRealKingK What do you mean, "the history of the local machine"? Because of how the SSH protocol works, the username MUST be sent by the client machine, so there's no way of keeping the client machine from knowing the username.
-
Dessa Simpson about 9 years@TheRealKingK PuTTY does NOT have you enter it into the server. You enter it into the console and PuTTY stores it in memory to send to the server.
-
-
TheRealKingK over 12 yearsDoesn't this still require the username to be on the client machine? I want to be prompted by the server for it.
-
TheRealKingK over 12 yearsThis is very interesting, but I don't want to log in as root. I want to be prompted for username by the server.
-
minhas23 over 7 yearsGreat !. my login user was manjeetsingh and all the machines identify me as manjeet. So setting user manjeet in ~/.ssh/config worked for me