zoukankan      html  css  js  c++  java
  • 新买服务器 设置ssh秘钥登录

    新增用户
    useradd -m youusername
    设置密码
    passwd youusername
    校验密码
    cat /etc/passwd | grep youusername
    删除用户
    userdel -r youusername
    -r 删除/home/youusername 也一块删除
     
    新增ssh key登录
    cd /home/youusername/
    mkdir -p .ssh && touch .ssh/authorized_keys && chmod 700 .ssh/ && chmod 644 .ssh/authorized_keys
    chown -R youusername .ssh/
     
    生成key 或者 本地生成可以之后 更改/home/youusername/.ssh/authorized_keys 把秘钥(公钥)上传上去
    ssh-keygen -t rsa -b 4096 -C "youusername@qq.com" -f /home/youusername/.ssh/authorized_keys
     
    配置ssh远程登录
    配置sshd_config
    vim /etc/ssh/sshd_config
    #允许密钥认证  如果没有该项 则忽略
    RSAAuthentication yes
    PubkeyAuthentication yes
    #默认公钥存放的位置
    AuthorizedKeysFile  .ssh/authorized_keys
    重启
    service sshd restart
     
     
     
    配置root权限
     
    chmod u+w /etc/sudoers
    vim /etc/sudoers
    %youusername ALL=(ALL) NOPASSWD:ALL
    chmod u-w /etc/sudoers
     
    Linux中普通用户用sudo执行命令时报”xxx is not in the sudoers file.This incident will be reported”错误,解决方法就是在/etc/sudoers文件里给该用户添加权限。如下:
    1.切换到root用户下
      方法为直接在命令行输入:su,然后输入密码(即你的登录密码,且密码默认不可见)。
    2./etc/sudoers文件默认是只读的,对root来说也是,因此需先添加sudoers文件的写权限,命令是:
    即执行操作:chmod u+w /etc/sudoers
    3.编辑sudoers文件
    即执行:vi /etc/sudoers
    找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
    ps:这里说下你可以sudoers添加下面四行中任意一条
    youuser ALL=(ALL) ALL
    %youuser ALL=(ALL) ALL
    youuser ALL=(ALL) NOPASSWD: ALL
    %youuser ALL=(ALL) NOPASSWD: ALL
    第一行:允许用户youuser执行sudo命令(需要输入密码).
    第二行:允许用户组youuser里面的用户执行sudo命令(需要输入密码).
    第三行:允许用户youuser执行sudo命令,并且在执行的时候不输入密码.
    第四行:允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码.
    4.撤销sudoers文件写权限,命令:
    chmod u-w /etc/sudoers
     
     
    禁止root登录
    vim /etc/ssh/sshd_config
      #禁止密码登录
    PasswordAuthentication no      
    #允许root认证登录
    PermitRootLogin no
    重启
    service sshd restart
     
    更改登录端口
    vim /etc/ssh/sshd_config
    Port 2287        #开放的端口
    重启
    service sshd restart
    开启防火墙端口2287
     
     

    我的个人首页http://www.songaw.com
  • 相关阅读:
    Nginx编译安装及平滑升级
    alertmanager 分组,抑制, 静默
    alertmanager 邮件告警&自定义告警模板
    alertmanager 高可用
    程序运行报错UnicodeDecodeError: 'utf8' codec can't decode byte 0x89 in position 0: invalid start byte
    Postman 导入curl 、导出成curl、导出成对应语言代码
    Python 字符串操作(截取/替换/查找/分割)
    In testLogin: indirect fixture *** doesn‘t exist
    postman 传参传递二进制流文件
    开发经验01
  • 原文地址:https://www.cnblogs.com/songanwei/p/15532464.html
Copyright © 2011-2022 走看看