(Linux)(Ubuntu) SSH server

  1. 安裝SSH Server

    apt-get install openssh-server
    

    或者

    apt-get install ssh
    
  2. 設定SSH Server

    • SSH設定檔(ssh_config)

      sudo gedit /etc/ssh/sshd_config
      
    • 開啟SSH Port(更改ssh_config)

      PORT 22
      
    • 禁止root帳戶登入(更改ssh_config)

      PermitRootLogin no
      
    • 限定特定使用者群組ssh登入(更改ssh_config)

      AllowGroups ssh
      
  3. 檢查SSH服務是否啟動

    ps ax | grep ssh
    
  4. Client端使用ssh連線至SSH server

    ssh user@server_ip
    
  5. Client端使用SSH Key連線至SSH Server

    • Client建立SSH Key (key1.pub與key1)

      ssh-keygen

    • Client上傳SSH Key公鑰(key1.pub)

      • Client操作上傳

        ssh-copy-id -i key1.pub user@server_ip
        
      • Server端操作,先藉由其他方法將公鑰複製至Server

        cat /path/to/key1.pub >> /home/user1/.ssh/authorized_keys
        

        注:不同使用者則為

        cat /path/to/key1.pub >> /home/user2/.ssh/authorized_keys
        

        注:單個使用者可有多組SSH Key

        cat /path/to/key2.pub >> /home/user1/.ssh/authorized_keys
        
      • Server端,調整authorized_keys檔案權限

        chmod 600 /home/user1/.ssh/authorized_keys