The process of connecting to the Linux machine is exactly the
same as connecting to the Windows machine.
We use the Enter‑PSSession.
We can say HostName, a different one this time.
It's a 143.
I'm going to say UserName, and we use our same username.
And then I'll say SSHTransport and press Enter.
It asks me for confirmation of the fingerprint.
I'm going to say yes.
And then it will ask me for the password.
I'll type the password in here.
It's going to wait for a second. And notice what happens here.
It says permission denied.
So let's type the password again.
It's going around again, and it'll come back and say permission denied.
I'm going to end it here for a second.
Now, I'm going to run the same command again,
and this time I'm going to adjust my account Trainer to be lowercase t.
I don't get prompted for the fingerprint this time,
but I'm going to type the password in, and then I get a PowerShell session.
So that was just be aware when you're connecting to Linux machines,
the username needs to be in the right format,
and it may actually be lowercase instead of an uppercase; whereas, in Windows,
it will just let you connect anyway.
So that's just a small note around connecting to Linux machines.
Now, of course, in order to utilize some of these kind of connections,
so I'm actually just going to type exit here. What we
can do here is say Get‑PSSession.
And when I enter the session,
you can see it's listed my previous session that I had created.
Now what I want to be able to do is create the Linux
session that I can then use to send commands because it's
okay having an interactive shell, which is Enter‑PSSession.
But what about being able to execute commands on it?
So I'm going to say session equals.
I'm going to use New‑PSSession instead of Enter.
My HostName will be exactly the same as it was before,
the IP address to my Ubuntu machine.
Remember,
my username is going to be lowercase. And then I'll add SSHTransport at the end.
It will ask me for the password again.
Notice no fingerprint this time.
And it should then confirm.
So let me just say session.
And sure enough,
I now have an SSH connection that I can then use to run other commands.
So what this means is I can say Invoke‑Command, which you've looked at before.
And this time, there's a property called Session,
and I am actually just going to use my variable called session here.
So my Invoke‑Command is going to run down a specific session.
Then I've got my ScriptBlock, which is what we've done before.
And then what I'll do is I'm just going to call a standard kind of option here
called PSVersionTable, and I'm not going to select anything else. I'm just
going to say PSVersionTable and leave it as that. And then I'm going to press
Enter. Notice it goes straight ahead down that session. It returns the platform
of Unix. It comes back and says it's Linux and Ubuntu. So I can now use that
session to perform various actions on the remote machine inside the SSH tunnel.
It's exactly the same process when we utilized Windows as well. So if I go back
to my command here and change to my other IP address, and we'll call it
sessionWin like so, I'll get prompted for the password again.
And sure enough,
I've got a SSH. Most important thing you can see under the transport property,
it says SSH. So let me clear that. I can then say Invoke‑Command. I'm going to
go back and change to use my sessionWin and the same thing again. And now it
comes back and says platform is Win32. Now,
of course, we can change this. I could get rid of that, and
now I can execute commands like this, and that gets ran
remotely over an SSH connection.
So it's fairly straightforward to do. The upfront work of configuration
just requires you to install the various components,
modify any configurations that might be needed, and then it's
as simple as using Enter‑PSSession if you want an interactive
shell or use New‑PSSession to be able to invoke commands and
send them down the tunnel.