---
title: "linux Centos 下非 root  用户执行shell的一些问题解决"
author: "flypeace"
date: "2015-06-02T00:02:36Z"
tags: []
categories: ["操作系统"]
slug: "linux-centos-root-shell"
draft: false
lastmod: "2015-06-02T00:02:36Z"
id: 2216042
url: "https://host.iteye.com/blog/2216042"
---

1、在linux系统上只有root用户才可以访问1024以下的端口号，其余用户不能访问

    今天在centos系统下，用非root用户启动 tomcat，默认端口是80，结果启动失败。

解决办法：

用sudo执行：

 

```
sudo ./startup.sh
```

 

 

结果报：

 

```
username is not in the sudoers file. This incident will be reported
```

 需要设置 用户 可以用sudo执行命令

 

 

2、让用户能够以 sudo 执行命令

以 root 用户执行：

 

```
visudo
```

 命令，编辑/etc/sudoers 文件。

 

在 root ALL=(ALL) ALL 下面添加一行  
username  ALL=(ALL)   ALL  
如果不想每次都输入密码可以用这一行  
username ALL=(ALL) NOPASSWD:ALL

wq保存。

 

再次用 加入的用户执行以下命令：

 

```
sudo ./startup.sh
```

 结果，每次都需要输入密码。

 

 

3、sudo执行脚本无需输入密码

执行：

 

```
visudo
```

 编辑，将 #%wheel 前面的#去掉：

 

 

 

```
## Allows people in group wheel to run all commands
 %wheel ALL=(ALL)       ALL

## Same thing without a password
 %wheel ALL=(ALL)       NOPASSWD: ALL
```

 wq保存。

 

将用户加入 wheel 组：

```
gpasswd -a YourUserName wheel
```

 

 

4、sudo执行脚本带不出环境变量

 

  经过上面的设置，再次用该用户启动 tomcat，发现：

 

```
sudo ./startup.sh
```

找不到 JAVA\_HOME 环境变量。

可以通过：

```
sudo -E  ./startup.sh
```

 执行解决。