linux常见问题

centos

  • 错误:error while loading shared libraries
    如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令

ubuntu

win10下的ubuntu子系统
安装完没有设置root密码,Ubuntu的默认root密码是随机的,
终端输入命令 sudo passwd,
然后输入当前用户的密码,enter,终端会提示我们输入新的密码并确认,
此时的密码就是root新密码。修改成功后,输入命令 su root,再输入新的密码就ok了。

vim /etc/ssh/sshd_config

修改
PermitRootLogin yes
PasswordAuthentication yes

service ssh start
//如果提示host问题
dpkg-reconfigure openssh-serve
//开机启动
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
touch /etc/rc.local
chmod 755 /etc/rc.local 
vim /etc/rc.local

如下内容

#!/bin/bash
service ssh start
exit 0

ssh key登陆

ssh-keygen -t rsa -c "邮箱"
cd ~/.ssh/
cat id_rsa.pub >> authorized_keys
cp id_rsa /mnt/c

此时c盘根目录有个id_rsa, 用SecureCRT 连接120.0.0.1端口22,设置证书为这个即可,当然你得找个其他地方放

更换镜像

apt安装速度巨慢,跟换阿里源

 lsb_release -c

记住显示的Codename,我的是bionic
打开http://mirrors.aliyun.com/ubuntu/dists/,看里面是否有你的,确定有后

cd /etc/apt
cp sources.list sources.list.bak
vim sources.list
//加入以下代码
deb http://mirrors.aliyun.com/ubuntu/ bionic main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main multiverse restricted universe

bionic替换你的,然后sudo apt-get update即可

目录权限

find -type d|xargs chmod 755
find -type f|xargs chmod 644

其他问题

vim编辑乱码,出现p字符

export TERM=linux

vi 编辑乱码
vi ~/.vimrc

set encoding=utf-8
set fileencoding=utf-8

保存即可

默认root

ubuntu1804.exe config --default-user root

ssh登录问题

dpkg-reconfigure openssh-server

vim /etc/ssh/sshd_config
//加入下面的
Port 22
ListenAddress 0.0.0.0
PermitRootLogin yes
PasswordAuthentication yes
StrictModes no

服务管理两种方式service和systemctl

1.service命令
service命令其实是去/etc/init.d目录下,去执行相关程序

# service命令启动redis脚本
service redis start
# 直接启动redis脚本
/etc/init.d/redis start
# 开机自启动
update-rc.d redis defaults

2.systemctl命令
systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动。
systemd对应的进程管理命令是systemctl

  • 2.1 systemctl命令兼容了service
    即systemctl也会去/etc/init.d目录下,查看,执行相关程序

systemctl redis start
systemctl redis stop
# 开机自启动
systemctl enable redis
  • 2.2 systemctl命令管理systemd的资源Unit
    systemd的Unit放在目录/usr/lib/systemd/system(Centos)或/etc/systemd/system(Ubuntu)

主要有四种类型文件.mount,.service,.target,.wants

.mount文件定义了一个挂载点,[Mount]节点里配置了What,Where,Type三个数据项
.service文件定义了一个服务,分为[Unit],[Service],[Install]三个小节
.target定义了一些基础的组件,供.service文件调用
.wants文件定义了要执行的文件集合,每次执行,.wants文件夹里面的文件都会执行

标签: ubuntu 阿里镜像 ssh登陆

发表评论: