Amazon EC2 的默认用户名为 *ec2-user*,在默认情况下,我们是没有办法修改这个用户的名称的,原因是这样的:1) 我们只能使用该用户登陆服务器;2) 登陆之后就无法修改它的用户名,但是我们还是有别的办法来修改它的。

直接不管它,创建一个新用户

这个方法其实足够了,创建了一个新的 EC2 Instance之后,使用下面的命令修改 root 帐户的密码:

[ec2-user@coxantu ~]$ sudo passwd root

这会提示你输入新密码以及重复输入一次,之后使用下面命令创建一个新用户:

[ec2-user@coxantu ~]$ su
密码:
[root@coxantu ec2-user]# useradd antu -p password

之后如下命令,修改 */etc/ssh/sshd_config* 文件

[root@coxantu ec2-user]# vi /etc/ssh/sshd_config

找到下面这部分并作相应的修改:

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes

修改为

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes

之后重启 *sshd* 服务:

[root@coxantu ec2-user]# /etc/init.d/sshd restart
停止 sshd:                                                [确定]
正在启动 sshd:                                            [确定]

之后我们再退出,重新使用密码认证的方式就可以登陆服务器了,比如:

cox@CoxStation:~$ ssh cox@ec2-23-22-97-113.compute-1.amazonaws.com
cox@ec2-23-22-97-113.compute-1.amazonaws.com's password:

   __|  __|_  )
   _|  (     /   Amazon Linux AMI
  ___|___|___|

https://aws.amazon.com/amazon-linux-ami/2012.09-release-notes/
There are 3 security update(s) out of 29 total update(s) available
Run "sudo yum update" to apply all updates.
[cox@coxantu ~]$

这个时候我们也没有必要再去删除前面那一个默认用户了,当然,如果你想你的系统“干干净净”的,那你直接删除它即可。

标签: none

评论已关闭