자바스크립트를 활성화 해주세요

p055 Goorm 컨테이너에서 다른 리눅스에 Pwsh Remote접속하기

 ·  ☕ 2 min read

Linux to Linux remote powershell 은 쉬운 설정방법에 속합니다. 왜냐하면 양쪽모두에 sshd가 대게 설치되어 있기 때문입니다. 어떤 프로토콜을 사용할까? WinRM? SSH? 고민하지 않아도 됩니다. 그냥 SSH를 사용하면 되니까요. 대게 포트도 오픈되어 있기 때문에 따로 오픈하지 않아도 됩니다.

설정은 서버사이드가 해당하는 쉘을 지정해 주는 것으로 설정이 끝납니다. Powershell Session은 Subsystem으로 powershell을 사용합니다.

설정하는 순서로는 당연한 얘기지만, 우선 리눅스에 Pwsh을 설치합니다.

지금까지는 goorm이 Ubuntu를 제공해 왔기 때문에 ubuntu에서 pwsh을 설치하는 방법을 많이 사용했습니다만, goorm의 ubuntu를 client로 사용하고, server는 CentOS를 사용하도록 하겠습니다.

Server-Side

microsoft 공식 문서의 방법을 사용하면 간단합니다.

curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

# Install PowerShell
sudo yum install -y powershell

# Start PowerShell
pwsh

만약 인터넷에 연결되지 않는 내부 노드이면, rpm 패키지를 그대로 가져와서 설치하는 방법도 설명하고 있습니다.

Client-Side

Client는 goorm의 ubuntu를 사용하므로 microsoft 공식 문서에서 ubuntu의 설치 방법을 사용하여 설치합니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Enable the "universe" repositories
sudo add-apt-repository universe

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh

sshd_config

공식문서 에서 리눅스의 sshd_config를 설정하는 방법대로 설정합니다.

다음의 내용이 /etc/ssh/sshd_config에 설정되어 있으면 됩니다.

PasswordAuthentication yes
Subsystem powershell /usr/bin/pwsh -sshs -NoLogo
PubkeyAuthentication yes

설정을 변경하였다면, sshd를 재시작합니다.

sudo service sshd restart

Connection

powershell을 실행하여 New-PSSession으로 Session을 만들어 줍니다. 이 session을 사용하여 파일을 복사하거나, Enter-PSSession등을 사용할 수 있습니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
PS /etc/ssh> $session = New-PSSession -HostName 50.195.36.199 -UserName root
The authenticity of host '50.195.36.199 (50.195.36.199)' can't be established.
ECDSA key fingerprint is SHA256:XOs3O2A6xJNK7vQPs0kaf52IitjNw6fo6w2iE9FvllM.
Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added '50.195.36.199' (ECDSA) to the list of known hosts.
root@50.195.36.199's password:
PS /etc/ssh>
PS /etc/ssh> hostname
goorm
PS /etc/ssh> $session

 Id Name            Transport ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            --------- ------------    ------------    -----         -----------------     ------------
  6 Runspace5       SSH       50.195.36.199   RemoteMachine   Opened        DefaultShell             Available

PS /etc/ssh> enter-pssession -Session $session
[50.195.36.199]: PS /root> hostname
testcentos
[50.195.36.199]: PS /root>

이상으로 linux to linux 의 powershell remote session을 만들어 보았습니다.

레퍼런스

공유하기

tkim
글쓴이
tkim
Software Engineer