Normally, when you start off with a machine with Amazon, or DigitalOcean, or one of the service providers, you'll get a user name and password to start off. That will be the way that you log in for the first time to the machine.
So for instance, with Amazon, it's typically called Ubuntu. That's the user that you get when you create Ubuntu instances on Amazon. Now, since we're using a virtual machine that's running locally, we don't have that. So what I want to start off by doing is creating our own custom user.
So I have logged into the machine using Vagrant SSH. And now I'm going to say Add User and create a user named cmather. You can call this whatever you want. And we need to run that. Be careful with pseudo-privileges.
And then I'm going to provide a password. Make it something simple, just for demonstration. So I'll use the word password. And then just press Enter through the rest of this
Now we have a new user named cmather. And I want to be able to log in as that user using SSH. So let's exit out of this session. And that will drop us back onto our laptop.
I'd like to use the SSH command to log in remotely to our virtual machine. If you want to learn about all the different options the SSH command takes, you can use the man pages. So I would say man ssh. And that will show you all the different options available.
With SSH, you provide a user name typically. So in this case, we created a user called cmather. And then you use the at symbol and then the address to the machine. So that could be something like 56.22 dot whatever. It could be an IP address. Or it could even be a host name, like something dot com.
Now, in this case, I'm not sure what the address of the virtual machine is. And that's because Vagrant has kind of hidden that from us. So we can use a special command in Vagrant called ssh-config. And that will tell us the configuration information for the SSH server.
So notice here that the host name is 127.0.0.1. So that's going to be local host. The port is 2222. And the default user is Vagrant. So we're going to change this a little bit, because-- I'll show you how to use identity files a little bit later. But we just want to log in as the cmather user now.
So what I can do is type SSH. And I'm going to give an option to SSH, which is the port option, so -p. And we want to use the 2222 port instead of 22, which is the default. So add an extra two-- an extra two 2's to the port. And now we're going to give the user name that we want to log in as, which is cmather@-- and then the host name, which is 127.0.0.1.
Now what this will do when I press Enter is ask me whether I want to establish the authenticity of the host. So just type yes here and press Enter. And next thing it will do is ask me for my password. So hopefully, you remember that. Mine was just password. So I'll type that in now. And here I am, logged into the Ubuntu instance as the cmather user.
So let's drop back to our laptop here. And what I want to point out is that you can have any user here. So it doesn't have to be cmather. It could be another user, for example, that's on this host. And this can be any different port that you want. So you have to check which port SSH is running on on the remote machine. And we determined this by asking Vagrant.
So Vagrant SSH, the command that we used originally is just a nice magical wrapper around the SSH command itself. And we determined what settings it was using by looking at the Vagrant SSH Config.