Skip to content

Instantly share code, notes, and snippets.

@nanmi
Last active June 15, 2021 04:38
Show Gist options
  • Save nanmi/1deaa9a2a692b71fcc0a6c4483ae1d47 to your computer and use it in GitHub Desktop.
Save nanmi/1deaa9a2a692b71fcc0a6c4483ae1d47 to your computer and use it in GitHub Desktop.
ubuntu修改用户名和主机名

Ubuntu修改用户名和主机名

{user_name}@{host_name}

参考链接:https://blog.csdn.net/Dan1374219106/article/details/106631364

修改主机名host_name

#进入root
$ su root

vim /etc/hostname

vim /etc/hosts
#修改下面内容
127.0.0.1 localhost
127.0.1.1 {host_name}
#重启host_name就修改好了

修改用户名user_name

# 这里需要修改sudoer文件、shadow文件、修改用户目录、修改passwd文件以及相应的组文件,至于这些文件的作用以及为什么要更改这些文件这里不赘述,只分享操作,有需要可以自行查询。
# 1.修改sudoer文件
sudo vim /etc/sudoers
#增加一个新的用户,如下
# User privilege specification
root    ALL=(ALL:ALL) ALL
jx      ALL=(ALL:ALL) ALL

# 2.修改shadow文件
sudo vim /etc/shadow
# 修改这个的开头内容 jx:$6$rf8MlEM4$MbHTJyTgmPgmHOSG1.gIPz77S7d/zK2M9gO8kLBGeA21ft4YidqMG2A9s21D6llbhxPbat63GAmzucF6zodTg1:18715:0:99999:7:::

# 3.修改用户目录
cd /home/
mv {旧用户名} {信用户名}

# 4.修改passwd文件
sudo vim /etc/passwd
# 修改一下的三处用户名 jx:x:1000:1000:jx,,,:/home/jx:/bin/bash

# 5.修改group文件
sudo vim /etc/group
# 将所有旧用户名名称全部换成新的保存退出即可
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,jx
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:jx
floppy:x:25:
tape:x:26:
sudo:x:27:jx
audio:x:29:pulse
dip:x:30:jx
www-data:x:33:
backup:x:34:

6. 删除旧的用户名权限
vim /etc/sudoers

# 重启即可
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment