添加用户
adduser mytxz
passwd mytxz
userdel mytxz
--------------------------------------------------------------------------------
赋予root权限
方法一:修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
然后修改用户,使其属于root组(wheel),命令如下:
usermod -g root mytxz
修改完毕,现在可以用mytxz帐号登录,然后用命令 su - ,即可获得root权限进行操作。
方法二:修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL
修改完毕,现在可以用tommy帐号登录,然后用命令 su - ,即可获得root权限进行操作。
--------------------------------------------------------------------------------
禁止root本地登录
修改/etc/pam.d/login文件增加下面一行
auth required pam_succeed_if.so user != root quiet
禁止root远程ssh登录
修改/etc/ssh/sshd_config文件,将
PermitRootLogin yes
修改为
PermitRootLogin no
--------------------------------------------------------------------------------
查看用户
查看当前登录用户
w
who
whoami
查看单个用户信息
finger apacheuser
id apacheuser
查看用户登录记录
last 查看登录成功的用户记录
lastb 查看登录不成功的用户记录
查看所有用户
cut -d : -f 1 /etc/passwd
cat /etc/passwd |awk -F \: ‘{print $1}’
--------------------------------------------------------------------------------
免密登录
本机生成public key:ssh-keygen -t rsa
复制公钥:scp ~/.ssh/id_rsa.pub mytxz@host:/home/mytxz/id_rsa.pub
cat /home/mytxz/id_rsa.pub >> /home/mytxz/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
生成第二个ssh key
ssh-keygen -t rsa -C "mytxz@foxmail.com" -f ~/.ssh/second-rsa
ssh-add ~/.ssh/second-rsa
windows多个ssh key的.config配置
Host git.coding.net_mytxz_coding
HostName git.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/second-rsa
User mytxz_coding
Host git.coding.net
HostName git.coding.net
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
User libo
--------------------------------------------------------------------------------
添加ssh端口
sudo vim /etc/ssh/sshd_config
Port 22
Port 10293
sudo ufw allow 10293 (ubuntu打开防火墙)
sudo service ssh restart (没升级openssh的)
sudo service sshd restart