xxx is not in the sudoers file解决方法

用sudo时提示”xxx is not in the sudoers file. This incident will be reported.其中XXX是你的用户名,也就是你的用户名没有权限使用sudo,我们只要修改一下/etc/sudoers文件就行了。下面是修改方法:

  1. 进入超级用户模式。也就是输入”su -“,系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。(当然,你也可以直接用root用)
  2. 添加文件的写权限。也就是输入命令chmod u+w /etc/sudoers
  3. 编辑/etc/sudoers文件。也就是输入命令vim /etc/sudoers,输入”i”进入编辑模式,找到这一 行:root ALL=(ALL) ALL在起下面添加xxx ALL=(ALL) ALL(这里的xxx是你的用户名),然后保存(就是先按一 下Esc键,然后输入”:wq”)退出。
  4. 撤销文件的写权限。也就是输入命令chmod u-w /etc/sudoers

Ubuntu配置Shadownsocks以及配置pac规则

周末没事将自己闲置的Thinkpad安装了最新的Ubuntu18.10版本,安装成功之后就想着将之前在自己的vps上配置的shadowsock服务使用上。

第一步安装shadowsocks

1
sudo apt-get install shadowsocks

第二步配置shadowsocks

安装完成之后默认的配置文件在/etc/shadowsocks/local.json,去将里面的配置修改成自己的即可。

1
2
3
4
5
6
7
8
9
10
11
12
{
"server":"xxx.xxx.xxx.xxx",
"server_port":xxx,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"xxx",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": true,
"workers": 1,
"prefer_ipv6": false
}

第三步启动shadowsocks

1
sudo sslocal -c /etc/shadowsocks/local.json -d start

第四步配置pac规则

1. 安装GenPac

1
2
sudo pip install genpac
pip install --upgrade genpac

2. 新建pac配置存放目录

用来存放用户自定义规则列表文件user-rules.txt和生成后的autoproxy.pac文件,例如我的放在home目录下

1
2
3
mkdir ~/soft/pac
cd ~./soft/pac
touch user-rules.txt

3. 生成autoproxy.pac文件

我使用的是github上托管的这份文件:https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
执行一下命令来创建autoprox.pac

1
genpac --pac-proxy "SOCKS5 127.0.0.1:1080" --output="autoproxy.pac" --gfwlist-url="https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt" --user-rule-from="user-rules.txt"

4. 配置系统代理

去Ubuntu设置 -> 网络 -> 代理设置设置代理,选择自动,配置url填写你本地的文件路径,例如:file:///home/xxx/soft/pac/autoproxy.pac

Ubuntu18.10配置rc.local自启动

Ubuntu新版本中已经不使用rc.local这种自启动方式了,熟悉旧版本的同学肯定是很不习惯的。那么新版本中如何配置rc.local呢。

  1. 自行创建 /etc/rc.local 添加以下默认内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.

    exit 0
  2. 在 exit 0 之前加入自定义内容

  3. 执行以下命令确保 rc.local 开机自启

    1
    2
    3
    sudo chown root:root /etc/rc.local
    sudo chmod 755 /etc/rc.local
    sudo systemctl enable rc-local.service

如何将 Debian Linux 中的默认的 Python 版本切换为替代版本

当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。你可以按照以下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。

1
2
$ ls /usr/bin/python*
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python3m

执行如下命令查看默认的 Python 版本信息:

1
2
$ python --version
Python 2.7.8

1、基于用户修改 Python 版本:

想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc 文件,添加新的别名信息来修改默认使用的 Python 版本。

1
alias python='/usr/bin/python3.4'

一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。

1
$ . ~/.bashrc

检查当前的 Python 版本。

1
2
$ python --version
Python 3.4.2

2、 在系统级修改 Python 版本

我们可以使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:

1
2
# update-alternatives --list python
update-alternatives: error: no alternatives for python

如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7python3.4 放入其中。

1
2
3
4
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

--install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以 update-alternatives 命令会自动将它设置为默认 Python 版本。

1
2
# python --version
Python 3.4.2

接下来,我们再次列出可用的 Python 替代版本。

1
2
3
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4

现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。

1
# update-alternatives --config python

img

1
2
# python --version
Python 2.7.8

3、移除替代版本

一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。

1
2
3
# update-alternatives --remove python /usr/bin/python2.7
update-alternatives: removing manually selected alternative - switching python to auto mode
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

Ubuntu安装NodeJs

之前使用apt命令安装node,但是安装之后每次执行都要sudo,比较麻烦。通过一下脚本可以将node安装到个人home下,以后执行就不用sudo了。

1
2
3
4
5
6
7
8
9
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/local
make install
curl -L https://www.npmjs.com/install.sh | sh