Logging to remote server without specifying username - ssh

Today I configured ssh keys access to my server. Then I tested them and by mistake I forgot to specify the user, so instead of doing it like that:
ssh username#myserver.com
I did it like that
ssh myserver.com
but I successfully logged in as username. How is that possible? How does ssh server know under which user to log me in? If it's a key, than it's possible that I'll have the same key added to multiple users, what's going to happen in this case?

if you didn't include the username in the ssh command it will take the username that you logged in with from the environment, so there is two possibilities for what happened, 1. the username which is related to the ssh key is the username that you logged in with, or the other username that you logged in with has the his public key in the authorized_keys file in the server side

Related

How to automatically login via Windows 10 Open SSH client (pre-stored password)? [Putty or BitVise SSH is not an option!]

Recently our web hoster (Domainfactory) changed the method to externally access our online mysql database. From simple ssh "port forwarding" to a "unix socks tunnel".
The ssh call looks like this (and it works!):
ssh -N -L 5001:/var/lib/mysql5/mysql5.sock ssh-user#ourdomain.tld
The problem: you have to enter the password every single time.
In the past I used BitVise SSH client to create a profile (which also stores the encrypted password). By simply double-clicking on the profile you'll be automatically logged in.
Unfortunately, neither the "BitVise SSH client" nor "Putty" (plink.exe) supports the "Unix socks tunnel" feature/extension, so I can't use these tools any more.
Does anyone have an idea how to realize an automated login (script, tool, whatever)?.
The employees who access the database must not know the SSH password in any case!
I got a solution. The trick is to generate a SSH Key pair (private and public) on client side (Windows machine) calling 'ssh-keygen'. Important: don't secure the ssh keys with a password (simply press [enter] if you're asked for a password, otherwise you'll be asked for the SSH-Key password every time you try to SSH). Two files will be generated inside 'c:\Users\your_user\.shh\': 'id_rsa' (private key) and 'id_rsa.pub ' (public key).
On server side create a '.shh' directory within your user's home directory. Inside the '.ssh' directory create a simple text file called 'authorized_keys'. Copy the contents of 'id_rsa.pub' into this file (unfortunately 'ssh-copy-id' isn't available yet for Windows. So you have to do the copy and paste stuff on your own.) Set permissions of 'authorized_keys' file to '600'.
Now you should be able to simply SSH into your server by calling 'ssh-user#ourdomain.tld' without entering a password. Create a batch file with your individual ssh-call and you're done.
Thanks to Scott Hanselman for his tutorial: https://www.hanselman.com/blog/how-to-use-windows-10s-builtin-openssh-to-automatically-ssh-into-a-remote-linux-machine

Vagrant: Log into an user account without ssh private keys

I created another user in a vagrant machine, and I would like to log into it by default. I wanted to know if there is a way of logging into it with it's password without having to put the password in plain-text Vagrantfile.

SSH config to restore user ssh access?

I have been locked out of ssh. I'm on the Google Cloud, so I can move the hd over and change the ssh config files, but after a few attempts, I cannot login still. The problem began shortly after I changed the password to the primary account, but since SSH was not using password authentication, I am surprised that affected SSH. I tried turning password authentication on, generating new keys, have Google's platform generate new keys, etc, but nothing has allowed me to log in.
I keep getting this error, regardless of key combo or whether or not password authentication is on.
Permission denied (publickey).
I have a slightly older backup (a couple hours, before the issue), and it's telling me too many authentication failures for any user (regarless of user#domain.com).
I was wondering if there are any config setting I can set to be able to log back in.
Not sure this belongs stackoverflow or serverfault but..
Try adding -vv to your ssh command. It shows a lot more debugging info
For example:
ssh -vv username#host
See if that gets you any hints! It could be a number of things, it searching for private key in the wrong place, etc.
The issue could be ssh keys saved in your local computer. Can you move the ssh keys from .ssh/ to a different directory in your local computer and see if that resolves the issue.
Or can you enable password authentication for your ssh and use -o flag with ssh command which forces non-key authentication to confirm if the issue was with the key: ssh -o PubkeyAuthentication=no username#
You also set MaxAuthTries to higher number in your sshd_config.

when i am trying to copy a local directory to remote server directory

When I am trying to copy a directory from local machine to remote server directory,It is asking for remote server password but i dint set any password for that.How should i solve it??
Have you test to enter login (session name) without password.
I think you must have set a password, even if when you use that remote server physically it logs in automatically, your user account will still have a password. Do you mean you're trying to use an ssh key with no passphrase?

Display Usernames in an ssh network?

I'm trying to ssh into a network. When I get there, it prompts me for the password to the username I had entered with it. However, I don't remember my username.
Is there any way perhaps to look at all the usernames listed within a network like this? If I can do that, I can figure out which one is mine.
ssh by default will use the username of the account you're running it from. E.g. If you're logged into machine A as user 'xyz', then by default it'll transmit "username = xyz" to machine B when you try to ssh to it.
if you want to force a particular username, then use
ssh remoteusername#remotehost.com
If you've completely forgotten your remote username, then no... ssh will not scan the remote system and tell you what accounts are on it. That'd be a hideously BAD security hole.
Im not completely sure what you have and what you don't. If you know the password and are logged in, you can run the command whoami to know your username.