Terminal and SSH access - General Topics

As a new Android user but experienced in Linux I wanted to explore the command shell. I've wanted to change passwords and have use the usual commands I would normally expect to be available.
I'd like to share my experience for any other new user and open the discussion for for additions and corrections. What I say here works on a Galaxy Mini S5570 but should be pretty generic. This really does need the phone to be rooted or much will be inaccessible.
Comparing 3 methods Terminal Emulator, DigiSSHD which is run from DigiControl and SSHDroid.
There is no concept of a root password as access is granted via superuser app. When you connect your id is set from the id of the app you are using to connect.
The simplest connection is via Terminal Emulator. It requires no network connection and gives direct access to the phone. The first thing is that you have no home directory so you are dumped into / the top directory. There is no .bash_profile, .bashrc or .profile so it's customisation is not obvious.
I tested SSHDroid and DigiSSHD using wi-fi. My ssh client was the excellent Putty on Windows7.
As default SSHDroid uses port 22 while DigiSSHD uses port 2222.
For a rooted phone SSHDroid has user "root" with password "admin". This is not your device's root password. You can think of it as an access password for SSHDroid. This access password can be changed in the options for SSHDroid. It is a good idea to do so stop others getting in just as you have done.
You arrive in a home directory data/data/berserker.android.apps.sshdroid/home and inside there you will find a .profile file so you can do some customisations there. The good news is that all the usual linux functions are available in ~/bin via the PATH variable it gives you and its own busybox.
Neither Terminal Emulator nor DigiSSHD give you these functions but this is a good way to do it.
Terminal Emulator by default gives you a PATH which includes /data/local/bin. This is set by Initial Command in the Preferences but I'm taking it as it is.
There was no directory /data/local/bin. This is good because we can create it and put our own stuff in there wihout having inconsistent clashes. Create it with the correct permissions. Copy the permissions of another directory in the path in my case I used /system/bin. To check the permissions:
cd /system
ls -l
The permissions were for bin are drwxr-xr-x with Owner/Group of root and Shell. So create the new directory.
cd /data/local
mkdir bin
chmod 755 bin
chown root.Shell bin
Now you can start creating your utilities. Before you do check that each is not already available by trying to run it. It might already be provided by Toolbox. To see what busybox can do type
busybox --help
To get your utility, assuming it is available in busybox create a symlink to busybox with the name of the utility. As an example this is how to create 'more' and 'less' and the standard 'vi'
cd /data/local/bin
ln -s /system/xbin/busybox more
ln -s /system/xbin/busybox/less
ln -s /system/xbin/busybox/vi
You can carry on activating your favourite utilities. Remember to check if it already there first and NEVER forget you are doing all this as root so take care...
Why do it this way and not use the functions provided by SSHDroid? Well as an ordinary user you may not have access and if you decide to uninstall SSHDroid you would probably lose it.
Now for DigiSSHD. The default user is android with a password of 123. I have not found how to change this yet so comments welcome. Your home directory will be something like /mnt/sdcard/Android/data/org.digimead.digi.ctrl/files/var/1d7a337e-7cf8-4b28-8039-baa894f7185f
There is a .profile file in your home directory that you can edit and add the line
export PATH=/data/local/bin:$PATH
This will give you access to the same utilities (so same versions) as you have with Terminal Emulator.
That's it. The rest is up to you. Which utilities you chose and which command line app suits you. I doubt that all the busybox functions will work on an Android system because it is not an ordinary Linux.
Which is better, SSHDroid or DigiSSHD? I don't know. I'll leave that for others to comment.

Are you the admin on this other site? Terminal and SSH Access Just curious as this is exact copy/paste post from that post with no links or attributions.

Related

Where are located the launched process at boot ?

Hi, i just rooted my hero yesterday.
I have some small capacities on linux, and i wnated to know if there is ( and where it is ) an equivalent to the /etc/init.d and different rc.x.d config. file for the process launched at boot. I wouldl ike to edit or delete some programs launching at startup which i don't need really to launch at startup Is it possible and simple ?
Ciao
Fred
Edit : stupid question... there is no vi on the system so no way to edit the file ..
I am even new than you to android rooting (just rooted my Sprint Hero 2.1 today!).
I loaded Fresh ROM 2.1.2 on my Hero today and there's an app called "ES File Explorer". It allows me to browse the unix-like filesystem, right to the directory you mentioned above.
I can click on the files and open them as Text, Executable, etc. Opening as Text even gives me two different text editors.
Unfortuantly, the file(s) you talk about are for readonly. You have to be logged in as a Superuser to edit them (as I found out today). The easiest way I found is to do it via a command-line prompt.
When you "root" your android phone, that means you are able to login remotely as another user. Such as the "superuser" account from the Android SDK. On Windows, after you have rooted your phone, you can do:
Code:
C:\android\tools\> adb remount
C:\android\tools\> adb shell
#
When you see that "#" prompt, you are now logged into your phone running the default shell (not sure which shell it is). So, now you can copy/open that file:
Code:
# cd \
# type init.rc | more
Of course u can't do squat from here. So, you have two options:
1) Change the permissions to allow you to modify it from the Android device itself (possible security issue if u download a broken app that wants to modify your phone).
Code:
# chmod 755 init.rc
Now you are able to modify the file locally, right on your device. No PC needed any longer. But again, it's a possible seucrity issue.
2) just pull the file from your device to your desktop pc, edit it, and push it back. Exit out of the # shell by typing "exit" and pressing enter. At the C prompt, pull the file:
Code:
C:\android\tools\> adb pull /init.rc C:\init.rc
That pulls the file from your android device and places it at C:\init.rc. You can obmit the C:\ part, which would place the file in your android Tools folder u are running adb from (mine is getting messy though).
Once you edit it to your liking, push it back to your device:
Code:
C:\android\tools\> adb push C:\init.rc /init.rc
And that's it.
most custom roms contain nano, which is also a possible way to edit files.
I updated my post to reflect actual directions on how to modify a system file like that.

GOOGLE TV & Better Terminal Emulator V4.0.3

First of all I would like to thank my intuitions on this discovery! the SONY Google TV can be rooted, well, at least the /system partition can be changed to read/write. I have not actually executed the command to do so, but I do know the necessary path to the Google TV's /system partition. I recently discovered that the the Google TV uses Better terminal Emulator pro V4.0.3, and I was looking around on the magicandroidapps.com WIKI and noticed that there was an application called TV Terminal Emulator Pro, but I think that was a throw-off. Better Terminal Emulator Pro version 4 works perfectly when trying to access system level permissions on SONY's (notice I said SONY) Google TV. Here are the facts. Hopefully someone can try the usual remount command and switch the system to read/write
1.install Better Terminal Emulator Pro (version 4.0.3 ONLY!) no other version will work
Hit the menu button in your SONY Google TV remote once the terminal has opened and in the default shell setting, choose the Almquist shell as the default!
2.type this command in the terminal
\ $/system/bin/ash
This will give you permission to execute all /system/bin commands(ash=advanced shell)
you will now have a prompt like this one below
\w \ $
3.you can now type this command to see all files in /system/bin directory:
\w \ $ls /system/bin
4. type this command:
\w \ $/system/bin/mount
NOTE: This command will give you a list of all partitions within the TV's file system!
NOTE:The system partition will be in the list of mounts called /dev/block/sda5. It is the only one of two mounts that is in read only mode.
NOTE: This directory is a ext3 file system, and this should be added in the remount command in terminal. Plaese give me some feedback on this matter because I know you GTV fans have been waiting on something like this!!
GOOGLE TV & Better Terminal Emulator Pro V.4.0.3 [UPDATE]
So have figured out how to issue the command to remount the system partition to rw, but it appers that I am not in root? For those who do not know the command, here it is:
\w \$ mount -o remount,rw -t ext3 /dev/block/sda5 /system
mount: permission denied (are you root?)
This is no big deal, this just means that we are getting closer to seeing just what this giant tablet can go. This also means that the command is corrects as well, for one to get an output like the one above., I will try to use another shell and see what commands will have to be executed and get back with all you GTV users.
NOTE: This is post is related to the (SONY Internet TV) and NOT the LOGITECH Revue
ALSO: Those of you who are trying to use ADB to control the television, The \$ adb root command cannot be executed in a production build of GOOGLE TV, which led me to go with Better terminal Emulator Pro.
GOOGLE TV & Better Terminal Emulator Pro V4.0.3 [UPDATE]
Hay guys, I was playing around some more with the terminal and I see that there ARE busybox commands present in the application.
I think the trick to rooting the SONY NSX32GT1 would be the CHMOD command. Entering this command while in the BASH shell when the emulator starts will give you the options for executing the command properly. if smeone can help me out with this command to change the permissions of the /system file system, that would be great. The CHOWN command may be of some use as well. I am almost 100 percent sure that if we change the permissions of the filesystem with one of these commands, we will be on our way to getting proper root access to out TVs!
If you are familiar with linux commands, please post a reply with the proper execution, and I will, in return, provide some very exclusive information about the television!
Here are some pics of the terminal up and running with busybox v1.16.2 built in.
i believe u may be speaking of commands like chmod -R 777 /system to give read write and execute permissions to user group owner .or chown root:root but to do any of that u must be root (the owner of most system files) or owner of said files in order to change owner group permissions and more. those commands come after a su or sudo in full bash. so u would still have to remount as rw. but the fact u got busybox installed is nice perhaps we can start looking at other root options if the busybox commands can be found during zerg or other overflow
Sent from my SPH-D710 using xda premium

Android Terminal Commands

Here are a few commands for Android in terminal. If you have any commands that you think should be here, just reply. Enjoy!
chmod - give/take rights away from files. The numbers you see in the how-to's is a little complicated. It has to do with the rights you are assigning the file or folder. http://wiki.linuxquestions.org/wiki/Chmod for further reading.
cat - look at, modify, or combine a file. You can also copy files with this command by "reading" it to another file instead of to the screen.
cd - change from one directory to another
cp - Copy a file from one location to another
dd - copies exact locations to other locations. Can be an entire drive, a folder, etc.
dd if= of=. uses an input file and an output file.
exit - exits the shell you are in. When you type su you start up a shell.
ls - lists all files with in a directory try ls - l too.
mv - Move a file from one location to another. At the same time you can rename a file.
su - Substitute User. We type this to switch to the root user. You need to type this command first to do a lot of the other commands.
tar - creates taped archives. Compresses files like winzip, 7zip, winrar and others tar /? for details.
rm - followed by a file name with delete the file sync - synchronizes any data on disk with data in memory. We type this before rebooting to ensure we've got all data written
Other commands of interest:
df - how much free disk space. In linux you can add a switch "df -h" but the "-h" does nothing for me on Android. top - like task manager, it displays running processes. in Linux the q key quits. On Android I don't know how to make it quit other than closing the app. uptime - displays how long it has been since you last rebooted the system.
busybox - a tool that combines many linux commands into a single compact file. Typing this displays all the commands at your disposal.
busybox df - a much easier to read display of free diskspace. This display shows how full (use%) each file system is.
Thanks
thank you so much, well for a noob like me very informative was looking for this kind from very long :laugh:
Substitute user XD you know it is superuser right?
free - see all free Memory from the Device
mid-kid said:
Substitute user XD you know it is superuser right?
Click to expand...
Click to collapse
Actually substitute user is also correct.
"The su command, also referred to as substitute user, super user, or switch user, allows a computer operator to change the current user account associated with the running virtual console."
Source: http://en.wikipedia.org/wiki/Su_(Unix)
Sent from my Galaxy Nexus using xda premium
So practically the basic linux comands are the same with android terminal!!!
I just noticed that the ping command is working just fine
Type ping 4.2.2.4 for example
rezo609 said:
If you have any commands that you think should be here, just reply. Enjoy!
Click to expand...
Click to collapse
svc data enable - turn on mobile data
svc data disable - turn off mobile data
svc wifi enable - turn on wifi
svc wifi disable - turn off wifi
svc help - show information about subcommands
For the top command mentioned in the OP, just type "top -n 1" and it will exit, leaving you with the readout at the time you executed the command. -n is for number of updates before stopping.
Also will add that the powertop command will show the top reasons for wakeups from idle.
Tnx
Metalcorpe said:
So practically the basic linux comands are the same with android terminal!!!
Click to expand...
Click to collapse
Yep
rezo609 said:
If you have any commands that you think should be here, just reply.
Click to expand...
Click to collapse
grep - Useful to apply filters to other commands. For example, to list only the apk files inside a folder:
Code:
ls /folder/to/list | grep apk
or to search a string inside a file:
Code:
cat /file | grep stringToSearch
logcat - Debugging tool, all the system messages are shown here. To show only the debug messages (useful when an app is giving FC without apparent reason), type:
Code:
su
logcat -d
mount - The most common use for this command is remount the system partition, to modify its content (be careful, you can easily brick your device!). Common usage (needs root):
Code:
Mount /system in Read/Write mode:
mount -o rw,remount /system
Mount /system in Read Only mode:
mount -o ro,remount /system
Saving command output to file. Type
Code:
command >> /folder/to/save/file
If the file doesn't exist will be created, otherwise, the info will be added to the end of the file.
You can also use:
Code:
command > /folder/to/save/file
If the file doesn't exist also will be created, but if the file exists its content will be deleted before add the info.
mount - Mounting a partition
umount - Unmounting a mounted partition
reboot - Reboot phone
stop - Shutdowns the GUI
start - Restarts GUI
above two commands can be used to get a fast reboot.
Also you my use the reboot command to do a faster restart to the device but your are going to lose any unsaved work
You must be rooted
First type : su
Then : reboot
Sent from my GT-I9505 using XDA Premium 4 mobile app
run program with command
I want to run "Applock"s lock all command. I have widgetsoid which can create shortcut for any command. How to do it? I am rooted.
SAVED ME!
toasterwater said:
svc data enable - turn on mobile data
svc data disable - turn off mobile data
svc wifi enable - turn on wifi
svc wifi disable - turn off wifi
svc help - show information about subcommands
Click to expand...
Click to collapse
Dude, thank you so much for posting this information. I had switched my MNVO service to a newer a phone, and this one was just sitting around. There were still things on it that I needed like some notes that I had saved. Because I had not used it in a while, and there was no data/cell service on it, I was out of luck (or so I thought) when I forgot my unlock pin. It wouldn't accept my google login information because there was no data connection. I COULD NOT GET INTO MY PHONE! I was dreading the possibility of having to factory reset, which would erase my notes and other things saved on there. On a whim and after MUCH Google searching, I was trying to find a way to reset the number of attempted pin locks to no avail. I was about to give up, but luckily, I remembered I had rooted it. And after downloading the latest SDK bundle, I came across your post. It allowed me to turn the wifi on my cell phone even though I was "locked out." Wouldn't you know that it very quickly picked up my home wifi signal. Because a data connection was enabled, I was then able to use my gmail login information to get into the phone. Your post saved me and prevented me from having to factory reset my phone and losing my information. Thank you so much!
netstat - show connections status in local device
...
rezo609 said:
Here are a few commands for Android in terminal. If you have any commands that you think should be here, just reply. Enjoy!
chmod - give/take rights away from files. The numbers you see in the how-to's is a little complicated. It has to do with the rights you are assigning the file or folder. http://wiki.linuxquestions.org/wiki/Chmod for further reading.
cat - look at, modify, or combine a file. You can also copy files with this command by "reading" it to another file instead of to the screen.
cd - change from one directory to another
cp - Copy a file from one location to another
dd - copies exact locations to other locations. Can be an entire drive, a folder, etc.
dd if= of=. uses an input file and an output file.
exit - exits the shell you are in. When you type su you start up a shell.
ls - lists all files with in a directory try ls - l too.
mv - Move a file from one location to another. At the same time you can rename a file.
su - Substitute User. We type this to switch to the root user. You need to type this command first to do a lot of the other commands.
tar - creates taped archives. Compresses files like winzip, 7zip, winrar and others tar /? for details.
rm - followed by a file name with delete the file sync - synchronizes any data on disk with data in memory. We type this before rebooting to ensure we've got all data written
Other commands of interest:
df - how much free disk space. In linux you can add a switch "df -h" but the "-h" does nothing for me on Android. top - like task manager, it displays running processes. in Linux the q key quits. On Android I don't know how to make it quit other than closing the app. uptime - displays how long it has been since you last rebooted the system.
busybox - a tool that combines many linux commands into a single compact file. Typing this displays all the commands at your disposal.
busybox df - a much easier to read display of free diskspace. This display shows how full (use%) each file system is.
Click to expand...
Click to collapse
if i wanted to delete a directory with data ? what would be the syntax
Set/View Network Host Name
Run the following as root
setprop net.hostname <new_hostname> // To Change Device Hostname
getprop net.hostname // To View Device Hostname
list of all android terminal commands
Open terminal or file explorer with root access
From root folder go to /system/bin
Type command :ls
The list contains all the terminal codes available
Enjoy!!
Disclaimer1: I'm not responsible if anything goes wrong while you try out the codes.
Disclaimer:man & help pages are not available on android terminal

Android Command Line Tools

Hi all, here is a package of command line tools I've put together, here's the readme with a few of the tools listed.
Android Command Line Tools
This Is Working Prefectly On Samsung Galaxy S3 'GT-I9305'
Your Phone Should Be Rooted To Perform These Steps!!!
Installation:
1. Copy The android-tools.zip To Your SD Card (Internal Or External) And Extract It
You Should Now Have A Directory Called 'android-tools'.
2. Open A Terminal On Your Phone And Type The Following
su
mkdir /data/tmp
cat /sdcard/android-tools/busybox > /data/tmp/busybox
cat /sdcard/android-tools/busybox-installer > /data/tmp/busybox-installer
cat /sdcard/android-tools/pkgs.tar > /data/tmp/pkgs.tar
cat /sdcard/android-tools/install.sh > /data/tmp/install.sh
cd /data/tmp
chmod 755 *
./install.sh
3. In Android Terminal Emulator Preferences, Set The Shell Path to '/system/bin/bash'
And Leave The Initial Command Blank.
4. Quit Terminal Emulator And Restart.
OpenSSH: ssh-keygen Save To '/data/local/home/root/.ssh/id_rsa'.
'ssh' And 'scp' Binaries Will Look For Keys In '/data/local/home/root/.ssh/'
So You Dont Need The '-i' Option, 'ssh-copy-id' Gets It From There Too.
Arduino:
There Is A Build Environment To Build And Upload Arduino Sketches With A Script Called 'arduino' To Wrap It Up
Type 'arduino --help' In Terminal To See Its Options, It Uses The Arduino-1.0 Core Library And I have Tested
Every Board And Can Confirm It Builds For All Boards Including 'micro' And 'leonardo'. It Uses 'avrdude'
'avr-libc-1.6.7' 'gcc-avr-4.5.1', I Wrote A 'arduino.nanorc' File For Writing Sketches Which Has All The
Functions And Constants Of The Arduino Core Library With The Same Colours As In The IDE.
Other Tools:
Some Other Binaries I Have Added Or Modified Are 'tar' With All Options Enabled, 'iwconfig', 'grep egrep fgrep'
With Colour And PCRE Enabled, '7zip', 'ipctool', 'shc' For Compiling Shell Scripts, 'ssh-copy-id', 'sed' With All Options
Enabled, 'macchanger', 'bootimg_baseaddr' In bash/sh, Compiled GNU 'core-utils', 'ncurses-hexedit', 'nmap', 'ngrep', 'nano'
'strace', 'gcc', 'g++', 'unpack-bootimg' In bash, 'unrar' And 'vim'.
Backtrack 5 ARM Is Configured And Ready To Go, Just 'mkdir /sdcard/Chroot'
And Copy Your bt5.img File Into It And Type 'bootbt', Then Edit The Scripts
For VNC Server 'startvnc' And 'stopvnc' To Reflect Your Screen Size, These
Are In The pkgs.tar
Replacing '/system/etc/mkshrc' With The One Included In This Package Enables Bash As Default In ADB Shell
If The Bash Binary Is Found In '/system/bin/bash' Else The Default Shell Will Drop Back To mksh.
Nano Does Not Save Through ADB Shell Using ^O Or '^X Then y' Method, Works Fine In Terminal Emulator App On Device.
There are more tools than listed above, here's the link> https://www.dropbox.com/s/yjumfljy7e1yoyc/android-tools.zip
If you're on an custom ROM and can't use the terminal emulator when you restart terminal emulator, get /system/lib/libncurses.so from stock ROM and use adb to copy it into /system/lib on your current ROM, I will fix this tomorrow.
Sent from my GT-I9305 using xda app-developers app
Please post the right link... this one is malformed.
sciurius said:
Please post the right link... this one is malformed.
Click to expand...
Click to collapse
op just updated the link, package is now ready for download again!
thank you, andreotti09!!!
greetz,
sUsH

[SCRIPT] sudo for Android (requires bash)

There's not a lot to explain here. Just a small novelty script I created on my spare time for fun that essentially does the same thing as sudo on desktop Linux. Each user / app gets its own password which you can set on first run or by typing "sudo passwd"
Usage:
Sudo <command> run single command as root, prompt for password to execute
Sudo passwd - change password for current user
Sudo --usage gives usage info
This is more of a novelty item than anything and isn't particularly practical since you can still just invoke root with su. Passwords are also stored in plain text in /sdcard so it's not exactly secure. But that being said here's the DL link
sudo for Android
Just place the script in /system/bin and chmod it 755.
This script also requires you have bash in /system/xbin, so stock ROMs are unlikely to work without some tinkering.
That being said, enjoy!

Categories

Resources