使用.pem連結

1. Download keypair file(.pem) from AWS when you created instance.

2. chmod 400 keyPairName.pem

3. ssh -i keyPairName.pem [email protected] (or [email protected])

免.pem認證檔連結

1. ssh-keygen -t rsa #(註:產生id_rsa, id_rsa.pub這兩個私鑰與公鑰,預設檔案位置在~/.ssh/內

2. scp -i keyPairName.pem ~/.ssh/id_rsa.pub [email protected]:~/.ssh/ # 複製公鑰至server上

3. ssh -i keyPairName.pem [email protected]

4. cat .ssh/id_rsa.pub >> .ssh/authorized_keys

輸入帳號、密碼登入

1. Login to your EC2 instance using your .pem file

$ ssh -i keyPairName.pem [email protected] (or [email protected])

2. Create a new user that will access the instance using a password:

$ sudo useradd -s /bin/bash -m -d /home/USERNAME  -g root USERNAME

3. Create a password for the new user:

$ sudo passwd USERNAME

4. Add user to sudoers file by using sudo visudo and add the following line:

$ sudo visudo
# Under the line "root  ALL=(ALL) ALL", and add yourself
USERNAME  ALL=(ALL) ALL

5. Change PasswordAuthentication no to PasswordAuthentication yes

$ sudo vim /etc/ssh/sshd_config

6. Reload that ssh configuration

$ sudo /etc/init.d/sshd reload
or
$ sudo service ssh restart

7. Now try logging out and logging back in with your new username

$ ssh [email protected]

Other

如果 sudo /etc/init.d/sshd reload 有問題的請確定有安裝下面兩個Libaray

$ sudo apt-get install openssh-client
$ sudo apt-get install openssh-server