MacใใSSHใงUbuntuใซใชใขใผใๆฅ็ถใใๆไฝๆไฝใใๆนๆณใซใคใใฆ็ดนไปใใพใใ
SSHๆฅ็ถใจใฏ
SSHใจใฏใๅ
ฌ้้ตๆๅทใ่ช่จผใฎๆ่กใๅฉ็จใใฆใๅฎๅ
จใซใชใขใผใใณใณใใฅใผใฟใจ้ไฟกใใใใใฎใใญใใณใซใงใใ
ใฏใฉใคใขใณใใจใชใขใผใใในใๅดใงไปฅไธใฎใใใซไบๅๆบๅใจๆฅ็ถๆใฎใใๅใใ่กใใใพใใ
- ไบๅๆบๅ
- โ ใฆใผใถใผใใฏใฉใคใขใณใ็ซฏๆซใง้ตใใข(ๅ ฌ้้ตใจ็งๅฏ้ต)ใไฝๆ
- โกใฆใผใถใผใไฝๆใใๅ ฌ้้ตใใชใขใผใใในใใฎใ~/.ssh/authorized_keysใใซ็ป้ฒ
- SSHๆฅ็ถๆ
- โ ใฏใฉใคใขใณใ็ซฏๆซใใๆฅ็ถๅ ใตใผใใผใซใใฆใผใถใผใฎๅ ฌ้้ตใใๅฉ็จใงใใใๅๅใ
- โกใชใขใผใใในใใใใๅฉ็จใงใใใใจๅ็ญใใใใฐใใฏใฉใคใขใณใใฏใใฆใผใถใผใฎ็งๅฏ้ตใใง็ฝฒๅใไฝๆ
- โขใฏใฉใคใขใณใใฏใใผใฟใจ็ฝฒๅใๆฅ็ถๅ ใตใผใใผใซ้ไฟก
- โฃใชใขใผใใในใใฏใๅไฟกใใใ็ฝฒๅใใจ็ป้ฒใใใฆใใใใฆใผใถใผใฎๅ ฌ้้ตใใๆค่จผใใๅ้กใชใใใฐๆฅ็ถใ่จฑๅฏ
ใชใขใผใใในใใปใปใปUbuntu(้ ้ๆไฝใใใๅด)
ใฏใฉใคใขใณใ็ซฏๆซใปใปใปMac(Ubuntuใ้ ้ๆไฝใใๅดใฎPC)
ๅ่
SSHๆฅ็ถใฎๅบ็ค็ฅ่ญใ็ฟๅพใใใๆนใฏไปฅไธใฎ่จไบใใๅ่ใใ ใใใ
SSHใตใผใใผใฎใคใณในใใผใซ
ใชใขใผใใในใ(Ubuntu)ๅดใซopenssh-serverใใใฑใผใธใใคใณในใใผใซใใพใใ
$ sudo apt update $ sudo apt install openssh-server
ใคใณในใใผใซใๅฎไบใใใจใ่ตทๅ็ถๆ ใซใชใใพใใopenssh-serverใฎ็ถๆ ใ็ขบ่ชใใพใใ
$ sudo systemctl status ssh
SSHๆฅ็ถใในใ
ใชใขใผใใในใๅดใงSSHใตใผใใผใ่ตทๅ็ถๆ
ใงใใใฐใSSHๆฅ็ถใงใใพใใ
ใฏใฉใคใขใณใ็ซฏๆซ(Mac)ๅดใฎใฟใผใใใซใงไปฅไธใฎใณใใณใใๅฎ่กใใพใใ
(ใชใขใผใใในใๅดใฎIPใขใใฌในใฏใใชใขใผใใในใๅดใงใip aใใณใใณใใๅฎ่กใใฆ็ขบ่ชใงใใพใ)
$ ssh [ใชใขใผใใในใๅดใฎใฆใผใถใผๅ]@[ใชใขใผใใในใๅดใฎIPใขใใฌใน]
ใในใฏใผใ่ช่จผใงSSHๆฅ็ถใงใใใฐๆๅใงใใ
ใๅฎ่กไพใ
$ ssh pi@192.168.1.3 The authenticity of host '192.168.11.44 (192.168.1.3)' can't be established. ED25519 key fingerprint is SHA256:XXXXXXXXXXXX/XXXXXXXXXXXX. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes โ yesใจๅ ฅๅใใฆEnterใญใผ Warning: Permanently added '192.168.1.3' (ED25519) to the list of known hosts. user1@192.168.1.3's password: โ ใฉใบใใชใผใใคใฎใญใฐใคใณใในใฏใผใใๅ ฅๅใใฆEnterใญใผ Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.5.0-14-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. user1@ubuntu:~ $ โ ใฉใบใใชใผใใคใๆไฝใงใใใใใซใชใ
้ตใใขใฎไฝๆใจ็ป้ฒ
ใฏใฉใคใขใณใๅดใฎPCใง้ตใใข(ๅ
ฌ้้ตใป็งๅฏ้ต)ใไฝๆใใ็ป้ฒใใพใใ
ใฏใฉใคใขใณใๅดใMacใฎๅ ดๅใMacใฎใฟใผใใใซใงssh-keygenใณใใณใใๅฎ่กใใ้ตใใขใไฝๆใใพใใ
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/XXXXXXXX/.ssh/id_rsa): โ ไฝใๅ ฅๅใใใซEnterใญใผ Enter passphrase (empty for no passphrase): โ ่จญๅฎใใใในใฏใผใใๅ ฅๅใใฆEnterใญใผ Enter same passphrase again: โ ่จญๅฎใใใในใฏใผใใๅๅบฆๅ ฅๅใใฆEnterใญใผ Your identification has been saved in /Users/XXXXXXXX/.ssh/id_rsa Your public key has been saved in /Users/XXXXXXXX/.ssh/id_rsa.pub The key fingerprint is: SHA256:XXXXXXX The key's randomart image is: +---[RSA 3072]----+ | | | | | . | | . . . | | S +o . . | | o +ooB *.E| | ++o*=B O+| | =oo*+o*.B| | ++oo+*+.=*| +----[SHA256]-----+
ใ/Users/[ใฆใผใถใผๅ]/.sshใไปฅไธใซ้ตใใข(ๅ ฌ้้ตใป็งๅฏ้ต)ใไฝๆใใใพใใ
ๅ
ฌ้้ตใปใปใปid_rsa.pub
็งๅฏ้ตใปใปใปid_rsa
Macใฎใฟใผใใใซใงใssh-copy-id [ใชใขใผใใในใๅดใฎใฆใผใถใผๅ]@[ใชใขใผใใในใๅดใฎIPใขใใฌใน]ใใๅฎ่กใใๅ
ฌ้้ต(id_rsa.pub)ใSSHๆฅ็ถใงใชใขใผใใในใๅดใซ้ไฟกใใฆ็ป้ฒใใพใใ
(ใชใขใผใใในใๅดใฎ~/.sshใใฃใฌใฏใใชๅ
ใฎauthorized_keysใซ็ป้ฒใใใพใ)
$ ssh-copy-id pi@192.168.1.3 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/XXXXXX/.ssh/id_rsa.pub" /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 user1@192.168.1.3's password: โ ใฉใบใใชใผใใคใฎใญใฐใคใณใในใฏใผใใๅ ฅๅใใฆEnterใญใผ Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'user1@192.168.1.3'" and check to make sure that only the key(s) you wanted were added.
ไธ่จๅฎ่กไพใฎใใใชใกใใปใผใธใ่กจ็คบใใใใใๅ ฌ้้ตใ็กไบใซใชใขใผใใในใๅดใซ็ป้ฒใใใพใใใ
SSHๆฅ็ถใ็ตไบใใๅ ดๅใฏใexitใใๅฎ่กใใพใใ
$ exit
ใชใขใผใใในใๅดใงSSHๆฅ็ถใฎ่จญๅฎๅคๆด
ๆฌกใซใชใขใผใใในใๅดใงSSHๆฅ็ถใฎ่จญๅฎใๅคๆดใใพใใ
SSHๆฅ็ถใฎ่จญๅฎใฏใ/etc/ssh/sshd_configใใใกใคใซใ็ทจ้ใใฆ่กใใพใใ
ใsudo geany /etc/ssh/sshd_configใใชใฉ็ฎก็่
ๆจฉ้ใงใใกใคใซใ้ใใฆไปฅไธใฎใใใซ็ทจ้ใใพใใ
ใๅคๆด็ฎๆใ
(็ฅ) # Port 22 Port 28987 โ ่ฟฝๅ (ใใผใ็ชๅทใใใใฉใซใใฎ22็ชใใๅคๆดใใใ0็ชใใผใใใ65535็ชใพใงใใ้ธใถ) (็ฅ) #PermitRootLogin prohibit-password PermitRootLogin no โ ่ฟฝๅ (rootใญใฐใคใณใ็กๅนๅ) (็ฅ) #PasswordAuthentication yes PasswordAuthentication no โ ่ฟฝๅ (ใในใฏใผใ่ช่จผใ็กๅนๅ)
MacใใUbuntuใซSSHๆฅ็ถ
Macๅดใฎใฟใผใใใซใงใssh -i ~/.ssh/id_rsa -p ใใผใ็ชๅท [ใชใขใผใใในใๅดใฎใฆใผใถใผๅ]@[ใชใขใผใใในใๅดใฎIPใขใใฌใน]ใใๅฎ่กใใใฐใใชใขใผใใในใ(Ubuntu)ใธใญใฐใคใณใงใใพใใ
ssh -i ~/.ssh/id_rsa -p ใใผใ็ชๅท user1@192.168.1.3 Enter passphrase for key '/Users/XXXXXXXXXX/.ssh/id_rsa': โ ่จญๅฎใใ็งๅฏ้ตใฎใในใฏใผใใๅ ฅๅใใฆEnterใญใผ Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.5.0-14-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status Last login: Sun Jan 21 09:50:31 2024 from 192.168.11.16 sv1@sv1:~$ exit
ใ่ฃ่ถณใSSHใตใผใใผใฎ่ตทๅใปๅๆญข
SSHใตใผใใผใใคใณในใใผใซใใๅพใฏWebใตใผใใผใ่ตทๅ็ถๆ
ใงใใ
SSHใตใผใใผใฎๅๆญขใ่ตทๅใ่ชๅ่ตทๅใฎ่จญๅฎใ่กใใใๅ ดๅใฏใไปฅไธใฎใณใใณใใๅฎ่กใใพใใ
SSHใตใผใใผใฎๅๆญข
$ sudo systemctl stop ssh
SSHใตใผใใผใฎ่ตทๅ
$ sudo systemctl start ssh
SSHใตใผใใผใฎๅ่ตทๅ
$ sudo systemctl restart ssh
่จญๅฎใฎใชใญใผใ
$ sudo systemctl reload ssh
่ชๅ่ตทๅใฎๆๅนๅ
$ sudo systemctl enable ssh
่ชๅ่ตทๅใฎ็กๅนๅ
$ sudo systemctl disable ssh
ใณใกใณใ