Automatically enter the password when switching the user using reverse CT

Source: Internet
Author: User

Yesterday, a netizen asked me how to automatically complete the password input work in shell. After a study, I found that this interactive work could not be implemented by a common shell. It is said that it could be done by using reverse CT, so I first learned about objective CT and shared the results with you:

Application 1:
You can switch from a common user "test" to a root user and automatically enter the root password. You do not need to enter the password at the terminal prompt.
Steps:
(1) VI autosu. Sh
(2 )#! /Usr/bin/CT-f // specify the path of the CT tool. If you do not know the specific path, run the "which CT" command.
Spawn Su-// use the "spawn" keyword to call the "Su -"
Failed CT ":" // After the Su-command is executed, a prompt indicating the password is prompted. For example, after you execute the Su-command, the terminal will prompt "Password:", so you can write your CT ":" or your CT-exact "Password:" here :"
Send "rootpasswd \ r" // here, verify CT uses send to automatically enter your root password to the prompt above.
Interact // The operation is complete.

Note: Pay attention to what you should pay attention to when executing the script. You cannot use sh *** according to your habits ***. sh to this line of CT program, will prompt that the command cannot be found, because CT uses not bash, so it will report an error. Execute./***. Sh directly .~ Remember!

Application 2:
After switching from a common user to the root user, execute the "ls" operation, call and execute AAA. Sh, and return the execution result. The interval is 10 s.
#/Usr/bin/CT-F
Spawn Su-// use the "spawn" keyword to call the "Su -"
Failed CT ":" // After the Su-command is executed, a prompt indicating the password is prompted. For example, after you execute the Su-command, the terminal will prompt "Password:", so you can write your CT ":" or your CT-exact "Password:" here :"

Send "rootpasswd \ r" // here, verify CT uses send to automatically enter your root password to the prompt above.
Keep CT "#" // when the prompt ends with #, It is the root permission;
Send "ls \ r" // use the spend method to call the LS command and press enter ("\ r ")
CT "#"
Send "Sh AAA. sh \ r" // call sh AAA. Sh to execute a script file AAA. Sh.
CT "#"
Send "Echo $? \ R"
Sleep 10
Interact

Write this first. There may be something wrong with it. Please kindly advise ~~~ Hey

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.