美文网首页
【HowTo】配置Ubuntu服务器

【HowTo】配置Ubuntu服务器

作者: 汶水一方 | 来源:发表于2017-08-14 04:56 被阅读13次

    作者:汶水一方
    2017.08.13

    本文不定期更新。

    (1) Enable SSH

    Install ssh:

    sudo apt-get install openssh-server
    

    重启sshd服务

    sudo service ssh restart
    

    (2) 设置静态Static IP

    1. sudo nano /etc/NetworkManager/NetworkManager.conf
      Change the value of managed from false to true
      Then reboot Linux
    2. Edit : sudo nano /etc/network/interfaces
      Add:
    auto eth0
    iface eth0 inet static 
        address 172.26.20.2
        gateway 172.26.1.1 
        netmask 255.255.0.0
        dns-nameservers 47.88.13.89
        dns-search dev.rokid-inc.com
    
    1. sudo ifdown -a && sudo ifup -a

    (3) 开机启动到命令行 Boot to CLI (not GUI)

    1. 先备份:
      sudo cp -n /etc/default/grub /etc/default/grub.orig
    2. 然后修改文件:sudo nano /etc/default/grub
      1. Comment: #GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
      2. Change: GRUB_CMDLINE_LINUX=”text”
      3. Uncomment: GRUB_TERMINAL=console
      4. Save and Exit
    3. Update grub via command: sudo update-grub
    4. Restart your computer and see the result.

    (4) 更新系统组件,安装基本工具

    sudo apt-get upgrade
    sudo apt-get update
    sudo apt-get install -y gawk
    sudo apt-get install -y vim
    sudo apt-get install -y screen
    sudo apt-get install -y nmap
    sudo apt-get install -y openssh-server
    sudo apt-get install -y curl
    sudo apt-get install -y git
    
    sudo apt-get install -y openssh-server vim screen curl git nmap gawk
    

    Note: VI is installed by default. But, if you don't install vim, there will be some problem when using vi to edit files. For example, in Insert mode, pressing arrow keys will generate ABCD characters instead of moving cursors around.

    • OPTIONAL: setup vi/vim
    sudo vi ~/.vimrc
    sudo vi ~/.exrc
    

    For each file above, add set nocompatible in the file.

    (5) 配置公钥认证

    • 上传ssh pub-key:在客户端电脑上,执行命令:
    ssh-copy-id -i .ssh/id_rsa.pub -p22 yourusername@dest_server_ip
    
    • 打开pubkey验证
    sudo nano /etc/ssh/sshd_config
    
    1. PubkeyAuthentication 必须为yes
    2. PermitRootLogin 设置为without-password (见下.)
    3. PasswordAuthentication 必须为no
    4. 重启sshd服务

    The values of PermitRootLogin in your /etc/ssh/sshd_config

    1. no: you cannot use root to login over ssh at all
    2. without-password: root login is allowed but only using a key, not a password.
    3. yes: both key and password are allowed.
    sudo /etc/init.d/ssh restart
    OR
    sudo service sshd restart
    //For CentOS 7
    systemctl restart sshd.service
    

    (6) 修改SSH登陆时的提示消息

    SSH登陆时的欢迎信息在以下2个文件中设置

    • Banner will be displayed before the actual login.
    • Motd will be displayed after the actual login.
    6.1 Banner
    1. 将要显示的消息文件插入/etc/issue.net (for BANNER)
    2. 需要在/etc/ssh/sshd_config中取消注释
      Banner /etc/issue.net

    Note: Text to ASCII GENERATOR
    http://patorjk.com/software/taag/

    6.2 Motd
    1. 将要显示的消息文件插入/etc/motd (for Motd)
    2. /etc/ssh/sshd_config中设置PrintMotd yes

    可能会出现motd消息打印2次的情况,PrintMotd yes改为PrintMotd no即可解决。详情待考。

    (7) 修改hostname 永久生效

    sudo nano /etc/hosts
    sudo nano /etc/hostname
    sudo reboot
    

    (8) 安装、使用screen

    sudo apt-get install screen
    
    • 执行screen
    • 然后repo sync
      这样可以关闭terminal,下次再次打开时,可以回到这个session
    • screen -list
    • screen -r session_id

    相关文章

      网友评论

          本文标题:【HowTo】配置Ubuntu服务器

          本文链接:https://www.haomeiwen.com/subject/jbyyrxtx.html