以下步骤设置密码,对Centos和Ubuntu进行彻底测试.
假设:
脚步:
创建一个新用户
useradd -m <yourname>
sudo su <yourname>
cd
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
将本地机器上的文件〜/ .ssh/id_rsa.pub的内容追加到EC2机器上的〜/ .ssh/authorized_keys.
chmod -R 700 ~/.ssh
chmod 600 ~/.ssh/*
Run Code Online (Sandbox Code Playgroud)确保机器允许sshing.在文件/ etc/ssh/sshd_config中,确保取消注释包含"PasswordAuthentication yes"的行.如果您对此文件进行任何更改,请重新启动sshd服务:
service sshd restart # On Centos
service ssh restart # On Ubuntu
Run Code Online (Sandbox Code Playgroud)您的无密码登录现在可以正常工作.在本地计算机上尝试以下操作:
ssh -A <yourname>@ec2-xx-xx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
Run Code Online (Sandbox Code Playgroud)让自己成为超级用户.打开/etc/sudoers
.确保取消注释以下两行:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)
添加到轮组.
usermod -aG wheel <yourname>
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
10932 次 |
最近记录: |