'명령어실행'에 해당되는 글 1건

Linux 원격지 명령어 실행 방법



리눅스에서 원격지의 서버의 명령어를 ssh 를 이용해서 실행할 수가 있습니다.


먼저 ssh-keygen 으로 키를 생성해서 ssh-copy-id 명령어로 원격지에 복사하여야 합니다.


# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:qFVgQxr7KJdSmg6kNfFGejV3WGZr3MCNwCZc/t3mpWw root@localhost

The key's randomart image is:

+---[RSA 2048]----+

|  . ooBo+=*o     |

|   = *o*+=o+.    |

| .+ B  oo + .    |

|o. B + o o . .   |

|o = + + S . . o .|

| o + o       + o |

|  . .         E  |

|             .   |

|                 |

+----[SHA256]-----+



생성한 키를 원격지에 복사합니다.


# ssh-copy-id root@www.example.com

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host 'www.example.com (133.130.111.206)' can't be established.

ECDSA key fingerprint is SHA256:/IMwZdnxDgCXr+hJAd118bqopeH+jgzb00yRDF+zjBA.

ECDSA key fingerprint is MD5:46:27:13:68:65:3d:7d:80:69:e0:ec:f3:ce:db:70:cc.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@www.example.com's password:


Number of key(s) added: 1


Now try logging into the machine, with:   "ssh 'root@www.example.com'"

and check to make sure that only the key(s) you wanted were added.



이제 원격으로 명령어를 실행해 봅시다.


# ssh root@www.example.com "df -h"

Filesystem      Size  Used Avail Use% Mounted on

udev            477M     0  477M   0% /dev

tmpfs           100M   11M   89M  11% /run

/dev/vda2        50G  5.0G   42G  11% /

tmpfs           497M     0  497M   0% /dev/shm

tmpfs           5.0M     0  5.0M   0% /run/lock

tmpfs           497M     0  497M   0% /sys/fs/cgroup

tmpfs           100M     0  100M   0% /run/user/0


이런 방법으로 원격지의 서버에 명령어를 실행할 수가 있습니다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,