2016年12月29日

edu2016遠端關學生電腦


1.老師機和學生機安裝openssh-server
sudo apt-get install openssh-server
2.老師和學生電腦産生公鑰和私鑰(不需sudo),老師機和學生機都要做
$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/teacher/.ssh/id_rsa):(按下Enter)
輸入自設的密碼二次
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/teacher/.ssh/id_rsa.
Your public key has been saved in /home/teacher/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mRmfkPr13+bVvg7/Tlp+S060+k0vuSTpC+3SrvekaKQ teacher@teacher-desktop
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|         .       |
|        +        |
|       . B .     |
|      . S +    . |
|       . ..o .. o|
|        .o..=.o=*|
|        E o=o*XO*|
|         .o=*+B&#|
+----[SHA256]-----+

3.把老師機的公鑰給學生

$cd ~/.ssh
$scp id_rsa.pub teacher@10.10.10.152:/home/teacher/.ssh/id_rsa.pub

出現
The authenticity of host '10.10.10.152 (10.10.10.152)' can't be established.
ECDSA key fingerprint is SHA256:AWqDWxm3s9YEIi7gdsCYH6PNRW/ALhLkqE8UFOL2UfU.
Are you sure you want to continue connecting (yes/no)?yes
  一定要打yes三個字
輸入密碼
teacher@10.10.10.152's password:
 id_rsa.pub                                    100%  405     0.4KB/s   00:00
公鑰複製好了


這樣會在家目錄下的.ssh資料夾中産生id_rsa 和 id_rsa.pub兩個檔案,id_rsa.pub就是公鑰
注意,這兩個檔案很重要,必要把把它設成維讀
$chmod 444 id_*.*

試著ssh teacher@10.10.10.152,第一次要輸入金鑰密碼(建立金鑰時輸入的密碼)和登入密碼
再做一次就不用再打密碼了

遠端闗機指令
ssh -t teacher@10.10.10.152 'sudo poweroff'

執行時輸入sudo密碼。

如果不想輸入sudo密碼,可以在學生電腦中編輯/etc/sudoers

%sudo   ALL=(ALL:ALL) ALL
改成
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL 
張貼留言