Linux無密碼登入

Password-less login

  1. Switch to hadoop user

    su - hadoop
    cd
    pwd

  2. Configuring SSH password-less login

    ssh-keygen -t rsa
    Enter file in which to save the key: [Return]
    Enter passphrase (empty for no passphrase): [Return]
    Enter same passphrase again: [Return]
    ls -l .ssh

    (copy public key to authorized_keys file)

    ssh-copy-id hadoop@localhost (把公鑰放到我本機我的帳號裡面,目的是讓自己hadoop可以在本機localhost無密碼登入)

    ssh-copy-id本身有資安風險,除非是在自己封閉網路的私有雲,或是全部自己管的叢集,否則不要貿然使用。

    測試:

  3. Test password-less login

    ssh hadoop@localhost
    exit # logout system

  4. Copy public key to other servers

    ssh-copy-id [email protected]
    ssh-copy-id [email protected]
    ssh-copy-id [email protected]
    ssh-copy-id [email protected]

  5. Test password-less login to other servers

    ssh [email protected]
    exit # logout system

    ssh [email protected]
    exit # logout system

    ssh [email protected]
    exit # logout system

    ssh [email protected]
    exit # logout system

  6. Check authorized_keys file

    cd
    cat .ssh/authorized_keys

參考資料:How Passwordless SSH Login Works. Security is my passion | by Michael Krasnov | Better Programming