在调用system命令读写硬盘序列号的过程中遇到问题,报错如下:

sudo: no tty present and no askpass program

发现此问题是由于帐号并没有开启免密码导致的 。

查找资料,解决方法如下:

方法一:

sudo isudo

然后在最末尾添加:

username ALL = NOPASSWD: /fullpath/to/command,/fullpath/to/othercommand

eg:
john ALL = NOPASSWD: /sbin/poweroff,/sbin/start,sbin/stop

会允许用户John在进行poweroff,start,stop的时候不需要密码。这里我使用了最简单的方式,如下:

john ALL = NOPASSWD: ALL

添加完成以后就可以无须密码进行sudo操作了。(亲测可用

方法二:

1    打开sudoers

vi /etc/sudoers

2    添加免密码

john ALL = NOPASSWD: ALL

读取硬盘序列号的方法:

if(system("sudo hdparm -I /dev/sda | grep Serial >> tmpGenuine.txt")>=)
{
QFile *tmpFile = new QFile("tmpGenuine.txt");//临时存放文件
if(tmpFile->open(QIODevice::ReadOnly|QIODevice::Text))
{
while(!tmpFile->atEnd())
{
QString tmpLine;
tmpLine = tmpFile->readLine();
tmpLine.indexOf(rx2);
genuineNum += rx2.cap();
}
qDebug()<<"genuineNum:"<<genuineNum;
}
tmpFile->close();
}
else
{
qDebug()<<"can not get the Serial Num";
return ;
}

How to fix 'sudo: no tty present and no askpass program'以及硬盘序列号的读写的更多相关文章

  1. sudo: no tty present and no askpass program specified(转)

    sudo: no tty present and no askpass program specified 2012-11-30 09:30 5040人阅读 评论(1) 收藏 举报 修改sudo配置文 ...

  2. 错误提示sudo: no tty present and no askpass program specified Sorry, try again.

    php调用shell脚本的svnup.php文件内容: <?set_time_limit(0);//$output = array();$ret = 0;exec("/usr/bin/ ...

  3. sudo: no tty present and no askpass program specified

    sudo: no tty present and no askpass program specified | 学步园 https://www.xuebuyuan.com/2157339.html 通 ...

  4. Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)

    若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11681474.html 原因: 本人最近正在尝试CI/CD,所以就使用了 Jen ...

  5. sudo: 没有终端存在,且未指定 askpass 程序

    问题:sudo: 没有终端存在,且未指定 askpass 程序 解决: sudo visudo 增加如下一行: neutron    ALL=(ALL)    NOPASSWD:ALL

  6. Fix network adapter not present problem in cloned CentOS

    (You can find a lot of articles on this from the internet. I just put it here for my own record.) It ...

  7. How to execute sudo command in remote host via SSH

    Question: I have an interactive shell script, that at one place needs to ssh to another machine (Ubu ...

  8. sudo问题汇总

    1. 注释Defaults requiretty Defaults requiretty修改为 #Defaults requiretty, 表示不需要控制终端. 否则会出现sudo: sorry, y ...

  9. Jenkins执行sudo权限的设置

    Jenkins系统中添加执行脚本的时候,有一些命令是需要sudo权限和来执行的,可以在root权限下添加一下Jenkins账号的权限 1.添加不需要密码可sudo执行指定命令的权限 cd /etc c ...

随机推荐

  1. MVC3升级到MVC4模型验证信息显示为英文问题及解决方案

    最近把项目从mvc3升级到mvc4,部署到服务器上出现了一个小问题,就是在表单里字段验证时,验证显示信息为英文,如下: The field 平均租金 must be a number 而在本地是好的, ...

  2. CSS样式基础知识

    CSS样式基础知识 CSS样式概述 CSS是Cascading Style Sheet 的缩写.译作“层叠样式表单”.是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言. 引用位 ...

  3. 创建简单的响应式HTML5模版

    创建简单的响应式HTML5模版 HTML5目前发展势头良好,已经逐渐得到大部分浏览器不同程度的支持.许多web开发者也已经学习到了不少关于HTML 5的基础知识并开始试图使用HTML 5制作网页.与此 ...

  4. rabbitmq在mac上安装

    1.安装brew 打开http://bash.sh  执行 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ ...

  5. Linux epoll总结

    Linux epoll总结 Linux  epoll epoll是Kernel 2.6后新加入的事件机制,在高并发条件下,远优于select.epoll最大的好处在于它不会随着监听fd数目的增长而降低 ...

  6. Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/var/AYXXXXXXXXXXX.pid). 错误解决方法

    /etc/init.d/mysql start无法启动MySQL错误信息如下: ERROR! MySQL server PID file could not be found! Starting My ...

  7. Left 、right join使用笔记

    用过很多次left join,right join,看到查询出的结果,知道可能是没用left join.或者right join导致的结果,但都是用一次,网上查一次使用规则,学到的东西只是皮毛.今天用 ...

  8. hdu1198--并查集

    Problem Description Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is ...

  9. WCF全双工数据传输

    项目结构: 客户端: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  10. java布尔值进行and和or逻辑运算原理

    先看看如下代码: public class Test { public static void test() { boolean a = true; boolean b = false; if (a ...