Connecting from Windows to Linux

If connecting from Windows, an SSH client must be installed. The following command uses the Chocolatey package manager (http://chocolatey.org) to install OpenSSH for Windows:

choco install openssh

Depending on the desired configuration, public key authentication may be enabled in the SSH daemon configuration file. A subsystem must be added to the file.

To enable public key authentication, set PubkeyAuthentication:

PubkeyAuthentication yes

An existing subsystem entry will likely exist toward the end of the file; this new entry can be added beneath the existing entry:

Subsystem       powershell    /opt/microsoft/powershell/6/pwsh -sshs -NoLogo -NoProfile

The sshd service should be restarted after changing the configuration file:

service sshd restart

The connection in this example uses SSH-key authentication. This requires an SSH key on Windows. If an existing key is not available, the ssh-keygen command can be used to create a new key pair. The command will prompt for any information it requires.

The private key created by this command will be used when connecting to a remote host. The public key is used to authorize a user and will be placed on the Linux system.

The public key can be obtained by running the following command on the system on which it was generated. This command assumes default filenames were used when generating the key:

Get-Content ~.sshid_rsa.pub | Set-Clipboard
~ is home

The tilde character may be used as shorthand for the path to the home directory. On Linux it is typically /home/<username>, and on Windows it is typically similar to C:users<username>.

~ may be replaced with the $home variable, or the $env:USERPROFILE environment variable on Windows, if desired.

The public key should be added to the authorized_keys files on Linux:

$publicKey = 'ssh-rsa AAAABG...'
New-Item ~/.ssh -ItemType Directory
Set-Content -Path ~/.ssh/authorized_keys -Value $publicKey

Once complete, a session can be created and used to interact with the Linux system:

$params = @{
HostName = 'LinuxSystemNameOrIPAddress'
UserName = $env:USERNAME
SSHTransport = $true
KeyFilePath = '~.sshid_rsa'
}
Enter-PSSession @params
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.153.38