在调用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. offsetWidth, offsetHeight, offsetLeft, offsetTop,clientWidth, clientHeight,clientX,pageX,screenX

    offsetWidth: 元素在水平方向上占用的空间大小.包括元素的宽度,内边距,(可见的)垂直滚动条的宽度,左右边框的宽度. offsetHeight:元素在垂直方向上占用的空间大小,包括元素的高度 ...

  2. Linux Wine with *.bat *.exe ( Photoshop and etc.. )

    Firtly all you need is to install wine on your computer. Mine is ubuntu 12.04 which is running KDE o ...

  3. centos6.5 搭建nginx1.6.0 +gridfs +mongodb2.4..10环境

    一) 缘由 因为公司业务需要,需要搭建图片服务器,需求很简单:读取+上传图片,当时第一考虑用nginx来作,但考虑到单纯用nginx来作,无法水平扩展和管理,一旦遇到海量图片,就无办法 扩展.所以考虑 ...

  4. ASP.NET发送电子邮件源码示例

    using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Mail; try { ...

  5. mpi和cuda混合编程的正确编译

    针对大数据的计算,很多程序通过搭建mpi集群进行加速,并取得了很好的效果.算法内部的加速,当前的并行化趋势是利用GPU显卡进行算法加速.针对并行性非常好的算法,GPU加速效果将远大于集群带来的加速效果 ...

  6. Android 获得各处图片的方法

    <pre name="code" class="java">//1,已将图片保存到drawable目录下 //通过图片id获得Drawable Re ...

  7. mysqldump备份错误:诡异的#mysql50#.mozilla数据库

    今天测试mysql自动备份功能 在red_hat_linux5系统下安装了mysql_5.5 系统提示执行脚本抛错, 手动执行脚本, 返回错误:mysqldump: Got error: 1102: ...

  8. ios-王云鹤 把UIdatePicker 嵌入到 UIActionSheet中

    这里简单的解释一下: -(void) setUpDatePicker方法用于调用UIDatePicker -(void) DatePickerDoneClick:(id) sender方法用于实现隐藏 ...

  9. 【转】HTTP Response Header 的 Content-Disposition

    因为听到有同事讨论JSP输出Excel文件的,就是在页面上有一个[导出]按钮,能够将查询结果导出到Excel文件让用户下载.有人说要用POI在后台生成临时的Excel文件,然后通过读取FileStre ...

  10. 部署 instance 到 OVS vlan100 - 每天5分钟玩转 OpenStack(138)

    上一节创建了 OVS vlan network vlan100,今天部署 instance 到该网络.launch 新的 instance “cirros-vm1”,网络选择 vlan100. cir ...