User loses group information when su to another user in an ssh session, why? - Android Software/Hacking General [Developers Only]

What I'm doing:
- I've built GNU emacs for native use on the phone.
- I run emacs in daemon mode on the phone, so I connect to it anytime with emacsclient, to continue working with regular files, run processes, etc.
- When logging in from the terminal on the phone, I'm currently user 10157, everything works:
Code:
$ id
uid=10157(10157) gid=10157(10157) groups=10157(10157),1015(1015),1023(1023),1028(1028),3003(3003)
- When I connect via ssh to the phone from a PC (I use DigiSSHd on the phone), it logs me in as a regular user 10282, everything works:
Code:
$ id
uid=10282 gid=10282 groups=1015(1015),1023(1023),1028(1028),3003(3003)
Emacs runs fine etc. However, this way I can't connect via emacsclient to the emacs process running under user 10157. This is desirable, since I don't want to start two emacs processes, since I want to continue working with files that I have open in emacs under user 10157.
Therefore:
Code:
$ su - 10157
Fine, I can run emacs etc. However, I cannot access the web.
Code:
$ ping -c1 google.com
You must have internet permissions to use ping. Aborting.
$ id
uid=10157(10157) gid=10157(10157) groups=10157(10157)
Thus I'm no longer in group 3003, necessary for internet access, besides other groups also.
Why does this group info get stripped, and how can I remedy this, so I can continue accessing the web when su as this user under ssh?

Related

Paranoia, the internet, and your phone.

This is probably not that useful unless (a) you're paranoid or (b) you need access to a secured network from your phone, however I managed to build openvpn and stunnel against bionic and the onboard openssl library. These are available at http://g1.fnord.to/crypto
OpenVPN requires root access and busybox. With this you can conceivably route all IP traffic through a server somewhere by use of the 'route' command, after the VPN link is brought up. This has been tested, and does not seem to affect phone functionality.
stunnel doesn't require root afaik so you should be able to run it from /data/local. This should allow you to encrypt web traffic at least, by setting the proxy via the 'Proxy Settings' app that's available with AnyCut.
Some how I think T-Mobile might get mad if you did this... They say they allow tethering but if you go over your 10GB limit and they can't see your traffic I would think they would want to know what is up.
Good idea and I know some people are that paranoid... but I see this getting people in trouble... or maybe it is just me.
This is GREAT. I've been looking for this since the day I got my G1. I tried to compile a statically-linked binary a while back, but it was HUGE and wouldn't do much before segfaulting at me.
This gets a 4 smilies because this is how I access my work network remotely from my desktop, and now I can access some of these servers for maintenance remotely from my phone! (I would have given it a whole row of smilies, but apparently that is frowned upon.)
Thanks a million for getting this working!
I probably won't be using it as a default route, but it can be a static route to my office servers for sure!
Just got done testing this to vpn to my workplace and it works awesome. It also routes all traffic while tethering thru the vpn tunnel route.
This has been the best reason for me to get root yet.
Wow this is dope... trying to set this up now so now I can connect to my server on the go. I hope t-mobile don't even see this cuz they will be trippin over why do you need to hide your traffic but this is great no more keeping record of wat you do. Next is gonna be p2p and I will even fell back for t-mobile network lol Thanks this great
neoobs said:
Some how I think T-Mobile might get mad if you did this... They say they allow tethering but if you go over your 10GB limit and they can't see your traffic I would think they would want to know what is up.
Good idea and I know some people are that paranoid... but I see this getting people in trouble... or maybe it is just me.
Click to expand...
Click to collapse
It would probably help for wifi usage. I never connect to public wifi with my G1 for this very reason. I have openvpn running on my router at home so I can tunnel into it when i'm wifi-ing on the go. If the G1 is in an area where there is no 3G coverage but there is public wifi, this might just be what the doctor ordered.
Can the G1 auto connect to openvpn whenever it connects to a network (via wifi), i want it to automatically poll mail for me..
The openvpn daemon is designed to autoreconnect if a keepalive ping fails. I would think if it is running in the background and you changed from Edge/3g to Wifi that it would force a reconnect situation, and it would re-establish the vpn through the new connection.
I will test this right now and get back to you
After testing, it works as expected. ~60 seconds after starting wifi I got the following message:
Inactivity timeout (--ping-restart), restarting
After that it re-established the tunnel through the new interface, and I was able to access machines at my office again.
I didn't know if anyone used a shell script to start/stop their VPN but I made the following so that I can easily start and stop it
Code:
#!/system/bin/sh
case "$1" in
'start')
modprobe tun
/data/local/bin/openvpn --config /path/to/config.ovpn --writepid /data/local/openvpn.pid &
;;
'stop')
kill -9 `cat /data/local/openvpn.pid`
sleep 2
rmmod tun
;;
*)
echo "Usage: $0 [start|stop]"
;;
esac
Instead of keepalive for timeout detection, it would be nice to have hooks called on ifup/ifdown, just like debian's /etc/network/if-up.d/*.
It would allow immediate reconnection upon switching interfaces (between 3G and Wifi for example), and also prevent a situation where an interface comes up, sets the default route, and traffic goes cleartext for 60 seconds until vpn reconnection.
I can think of a lot of other uses for such hooks. Does android offer them?
If we're certain the hooks do not exist natively, I'll find a non-polling way to provide them.
I couldn't find an android interface for ifup, so I just used the netlink notifications, via ip(8). Note that you need the real iproute2 ip binary rather than the busybox one. Probably awk as well - I didn't check since I use debian binaries rather than busybox.
Here's how you use it:
Code:
ip monitor route | awk -W interactive '/^default/ {system("/data/local/bin/ifup " $5)}'
It'll execute /data/local/bin/ifup whenever the default route is changed, and pass the interface name as $1. For 3G/GPRS the interface name is usually rmnet0, whereas for WLAN it is if<num> where num is increasing on every insmod, probably indicating a leak in the tiwlan driver.
If you want it to reconnect openvpn whenver the route changes, you should probably
Code:
killall -USR1 openvpn
for any interface other than tap0 (or whatever you call your openvpn interface).
The above method can be used for earlier events such as link-up, but I figured a default route would be the best time to start openvpn. For extra paranoia, you might want to use iptables to prevent connections to anything other than openvpn on tiwlan0, and have an "up" line in your openvpn config file to set the default route through your vpn when it comes up.
When I get around to write a nice script that does the above, I'll post it here.
How much space are we talking about using with native iproute2, awk, and other binaries? I would think the amount of space used is getting rather large. I guess that it quickly becomes a good time to start using the SD card to store apps.
I've not wanted to repartition my card, but I could always make a FS image and mount it 'mount -o loop' style.
As for instant-on, I'm not using this for paranoia like some are, so instant doesn't really matter to me nearly as much as it could otherwise.
Space requirements - I don't know how much it takes with the libs since I just use it inside a debian chroot and it's all on the sdcard. I need debian anyway, to run certain X apps, etc, so for me it's not a waste of space. Anyway, if you just build iproute2 and awk, or even your own binary that just creates a netlink socket and blocks on it, it shouldn't take a lot of space. Or, if you happen to have python on the phone, it can be done in a few lines of script instead of another binary.
Re instant on, I find it better, not just for paranoia reasons (e.g. ensuring that I never send a cleartext pop3/imap password over wlan), but also for long-running connections such as ssh. If I run them over the vpn interface, I have a fixed IP and the connections persist. If, on the other hand, I create the connection directly over 3g/wlan/gprs, it'll die as soon as I change interfaces. Therefore, I'd rather run all long-running connections over openvpn. IP mobility RFC implementation would be more efficient but as long as it's not an option, a vpn will do.
By the way, do we currently have a way to tie a script/executable to an icon/shortcut, or do you run your script from a terminal?
My understanding is there are problems running apps from a gui shortcut.
http://forum.xda-developers.com/showpost.php?p=3142661&postcount=93
I run everything I do from a terminal.
I guess we need a small loader then. Something that calls Exec.createSubprocess(), just like Term.apk does. Each app will have a symlink to this ShellLoader.apk, which will execute scripts based on the name it was executed under. Another one for the TODO list
From Term.java:
Code:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Log.e(Term.LOG_TAG, "onCreate");
setContentView(R.layout.term_activity);
mEmulatorView = (EmulatorView) findViewById(EMULATOR_VIEW);
int[] processId = new int[1];
if (TEST_MODE) {
// This is a vt100 test suite.
mTermFd = Exec.createSubprocess("/sbin/vttest", null, null);
} else {
// This is the standard Android shell.
mTermFd = Exec.createSubprocess("/system/bin/sh", "-", null,
processId);
}
final int procId = processId[0];
final Term me = this;
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
me.finish();
}
};
Can we use Exec.createSubprocess() as in this above but call "/system/bin/su /data/local/bin/APPLICATIONNAME" to make the Superuser app prompts for root among other things?
Maybe create a user interface that lets you enter what you want in the place of '/data/local/bin/appName' and then when it creates the shortcut also asks if that application needs root?
It could be a list of shortcuts that is selected from a list then. Look like a list of bookmarks perhaps?
I don't know enough of the android environment to know how realistically we could do something like that.
looks like that code example from above is old. Current source from git looks different, but the call looks similar enough. I will play with it here shortly.
Yes, we could do that, including su, but be careful with it
Re bookmarks inside a single loader, I think we can do even better:
We can have a single application called Loader, and call it with different parameters using AnyCut. AnyCut has a "make your own shortcut" option, where you can provide Action, Data and Type. I'm not familiar with the Android environment yet, but I guess the Action can point to the loader, and the Data can be a script name to be executed. This way, a single .apk can be used for starting many native programs.
If implemented that way, I suggest stripping slashes from Data and prepending with /data/local/scripts/ or a similar directory, so that it can only execute scripts the user meant for it to run, rather than arbitrary shell commands. /data/local/scripts/ can contain symlinks to scripts/apps the user wishes to execute from the Android interface. It's more secure that way, while retaining usability.
Makes sense?
Certainly does. You wouldn't want someone to be able to 'rm -rf /' or anything like that.
I think I like restricting it to /data/local/scripts and forcing us to symlink or place any scripts we want to be able run in that path.
Also agree with stripping slashes. There might be other sanitizing that we would want to do to keep malicious actions from being performed.
I would think strip any special characters that have special meaning to the shell * | < > ` etc. If we want to do anything that requires these, we put it in whatever shell script and then just call the script.
Maybe the best route is to just scan the /data/local/scripts folder and allow the user to select from a list.
In any case, whoever does this already has root, so it is just as easy to launch a terminal and break everything from there.
Just a few brainstormed thoughts.

Replacement for craptacular adb shell

Hey everybody. I'm on windows and adb's shell just keeps on pissing me off. Mainly, how pressing tab actually inserts a tab rather than tab completion . I'd really like to do something about this.
Here's a list of the things i've tried to get rid of this super-annoying behaviour.
-rolled a cross-compiler toolchain (glibc-based) for my phone (HTC Magic) and cross-compiled bash (in a vm). I actually made this work even with dynamic linking, and can start bash from within an instance of "adb shell". Unfortunatly, this doesn't change the tab behaviour, which appears to be baked into adb rather than a problem with the default shell.
-I thought i'd try something fancy by doing...
adb shell mkfifo /fifo
adb shell "bash > /fifo < fifo 2> /fifo"
adb forward tcp:9001 dev:/fifo
and starting putty in raw mode, connecting to localhost:9001. Unfortunatly, all is what happens is i get an echo of what i type and if i press enter a few times putty spits out ": command not found". I can't see why this shouldn't work but I suspect i'm Doing It Wrong.
-Searching the forum revealed puttycyg, which is actually really handy but unfortunatly suffers from the same tab completion problem as using adb shell in cmd.exe
How do you guys do it? Am I onto something with the adb forward thing? If so, how do I make that work?
I have also compiled bash but I have tab completion though adb. I do however use Linux as my desktop OS and am connecting through Konsole. So you could just try to install KDE for Windows. I know that I've looked for good terminal applications for windows but found none. They're all **** compared to what's available on nix.
This is my simple bashrc:
Code:
# If interactive do nothing.
[ -z "$PS1" ] && return
export HOME="/sdcard/"
PS1='[email protected]\h:\w\$ '
Also it's full of aliases for busybox. By replacing built in ls and similar you even get nice colors But still no line editing for some reason. I figure I might just need a proper libreadline or similar for that.
If anybody's interested in how I got this working, i cross-compiled socat for the droid. Required configuring with --disable-termios and manually editing config.h to set the #define for CRDLY_SHIFT and a couple other *_SHIFT macros to some values i found in Config/linux-2.6.24.h (or something similar, posting from memory here)
Once socat is on the phone, I made it pipe data from a bash shell to a unix socket it is listening on:
socat unix-listen:/dev/adbsock,fork exec:"/bin/bash -li",pty,stderr,setsid,sigint
(command shamelessly copied from http://superuser.com/questions/123790/socat-and-rich-terminals-with-ctrlc-ctrlz-ctrld-propagation ).
Then, on the pc i run adb forward tcp:9001 localfilesystem:/tmp/adbsock
And if i connect putty to localhost:9001 in raw mode (disabling line editing and local echo) I get a fairly complete bash shell that you can not only use tab completion on but even vi works
Again, posting from memory here so if anyone wants to try this and is running into problems i can dig it up from my ~/.bash_history.
Any chance you can post your socat port?
The tab completion thing is driving me insane! I don't understand why the ADB shell in *nix is proper, but the windows version sucks so much hairy donkey balls.
I've been using Ansicon so I at least get color in my shell, but ADB still mangles tab, and I don't even want to talk about what it does to Nano. Ugh!
Oh wow, this takes me back. I don't even have my android phone anymore (cancelled the contract due to terribly crap network service, and (unfortunately) the iPhone was the best phone in its price range from my new carrier).
So I don't have any files to give to you...
But, from what I can remember, to make it work, I built a cross binutils and gcc loosely following the instructions from the LFS book, compiled glibc + a few other libs socat wanted with it, and then socat itself, and then bash. I then copied the cross libc.so.6, ld-linux.so.2 (or whatever it's called on ARM) and all the libs socat wanted to /lib on the phone, and the socat and bash binaries to /bin. It's convenient that android keeps its important stuff in /system because it means you can avoid screwing around with your toolchain to make it look for a dynamic linker in some location other than /lib.
From memory socat was the only thing I had problems compiling, and thankfully I've already posted roughly what i had to do to it to make it build (because there's no way I remember lol)
Sorry I can't be more helpful!

Automatic wireless folder sync app needed

Hi,
I have looked around and cant seem to find an application quite fitting.
All I want is an app that will wirelessly sync just a folder automatically when I have my WiFi turned on, is there an app that can do this?
i.e. Come home from work, turn on wifi and it just syncs.
Many thanks
To any developers about: How hard would something like this be to make?
I think dropbox does that?
Dropbox syncs a folder on multiple devices with a folder on dropbox server.
There is also an app called PCFileSync that syncs a folder over wifi between the phone and a samba share. I am turning it on with Tasker once it connects to my home ssid. Works great!
Sent from my Desire HD using XDA App
samba share? hm........
rsync and ssh would be a much better choice and cleaner, just a script to run.
synflex said:
samba share? hm........
rsync and ssh would be a much better choice and cleaner, just a script to run.
Click to expand...
Click to collapse
http://a-more-common-hades.blogspot.com/2010/07/backup-photos-with-rsync.html
Tasker+Rsync, and combine it with a ssh key and you can automate it easy.
BTW, I decided to do this today.. I have one which backs up /sdcard/DCIM, and another which backs up the entire sdcard, both over wifi to my Fedora Linux workstation. I'll have to figure out how I want to execute these, but I can do it from GScript Lite, Tasker, whatever floats my boat.
Here's the notes I took, just in case I have to do it again in the future, hope it's useful to some folks..
# Get dropbear/dropbearkey from http://www.elkins.org/dropbear.tar.gz
# Get ssh off device and follow instructions (references at the end) to fix it, name fixed file "sshfxed"
# Remount /system rw
~/AndroidSDK/tools/adb shell
su
mount -o rw,remount device /system
#exit back to Linux shell
Click to expand...
Click to collapse
# Install dropbear and sshfixed from adb push
~/AndroidSDK/tools/adb push sshfixed /system/xbin/sshfixed
~/AndroidSDK/tools/adb push dropbear /system/xbin/dropbear
~/AndroidSDK/tools/adb push dropbearkey /system/xbin/dropbearkey
Click to expand...
Click to collapse
# Now get into adb shell and execute in Android..
mkdir /system/etc/dropbear
chmod 4755 /system/bin/dropbear
chmod 4755 /system/bin/dropbearkey
Click to expand...
Click to collapse
# Create keys
dropbearkey -t rsa -f /system/etc/dropbear/dropbear_rsa_host_key
dropbearkey -t dss -f /system/etc/dropbear/dropbear_dss_host_key
Click to expand...
Click to collapse
# Copy and paste the public DSS key the dss command above outputs and put it in ~/.ssh/authorized_keys on intended host. If you need to know more here, google for how to use ssh keys on Linux hosts. Basically if you're going to [email protected], on machine1 under user account "user" you create a file named authorized_keys in the .ssh directory with the output of the previous command, it tells you it's the 'public key', which is what you want to copy. It has to be all one line.
# Now actually use it all and rsync sdcard to your host For debugging, I suggest trying the "sshfixed -l USER -y -i /system/etc/dropbear/dropbear_dss_host_key" part just by itself and make sure you can ssh to your machine WITHOUT any prompting, password, etc.
~/AndroidSDK/tools/adb shell
# the following is all one line..
rsync -rltDv --chmod=u=rwX,g=rX,o=rX -e "sshfixed -l USER -y -i /system/etc/dropbear/dropbear_dss_host_key" /mnt/sdcard [email protected]:/your/path
Click to expand...
Click to collapse
-- References
Get dropbear - http://forum.xda-developers.com/showthread.php?p=8220181
Set up dropbear - http://forum.xda-developers.com/showthread.php?t=442754
Fix ssh client to use urandom - https://www.heiher.info/1592.html
Use it all to rsync over wifi - http://a-more-common-hades.blogspot.com/2010/07/backup-photos-with-rsync.html
Another vote for Dropbox, it works great! Look for referral codes in the comments on Market for some additional free storage. I use it all the time for pictures and vids for the family.
Sent from my HTC Desire using the XDA App
I use S&K sync.
Horrible user interface but once things are set up you need only to start the client on your phone and press the "Start Sync" button.
Supports multiple configuration sets (local/remote directory pairs, ip address, etc), each can be started separately.
Google: "SK sync android"
khaytsus said:
http://a-more-common-hades.blogspot.com/2010/07/backup-photos-with-rsync.html
Tasker+Rsync, and combine it with a ssh key and you can automate it easy.
Click to expand...
Click to collapse
I'm actually syncing to 2 android phones, with dropbox, rsync and dropbear.
Dropbox is good for documents and such, with small filesize and possiblity of sharing with others.
Using rsync for large files like movies and music folders, also some pictures, notes, keepass, and stuffs I like having around, things that's only going around between my laptop and phone.
Running a crontab that scans for my phone in adb devices, if found, pull a "last sync status" file, if interval > 1 hour or changes made locally, do a local notify-send till rsync is done, then execute dropbear on phone, rsync remote and local, kills dropbear, then push last sync file.
This way, no resources is wasted on the phone, all scanning and verification of device, system, and files were done on laptop.
At the same time I'm monitoring my development phone with frequent ssh rsync when it's in range, push updates, kernels and such across in proper folder structure.
This will ensure changes or new kernels were pushed to phone ready for testing.
Could use the same script for both phone, be it adb+ssh+rsync or pure ssh+rsync, but I personally don't like having sshd running in background when I'm connected to wifi hotspot.
Cleaner this way, less resources wasted on phone, and I can have full control over what, where, and when to sync.
I do realise that there isn't much choice for syncronization in the wild, thus you may like yo try something along the same idea, and you may get your own perfect combo to sync.
P.S. backing up, restoring or syncing bookmarks from browser.db and such could be done this way.

[Q] [?]Terminal emulator commands

i've been searching for days and i have found very little information about how to launch .apk in terminal emulator..
i can get to browser by:
am start -a android.intent.action.VIEW h ttp://ww w.anywebsitehere.co m(<<no space between those letters)
But, how can i run other apps like mms, contacts, etc?? im not a linux professional but im extremely interested in all of the aspects of how these systems work. seriously considering going to school and making a career out of it.
any and all help is greatly appreciated.
Droid1/CM7.1/
You are not specificly launching the browser, but creating a view intent for an URL, for which the browser, but any other app that has an intent for this registered, will offer itself.
Why do you want to start apps through the command line?
thank you for responding. i figured it was something i didnt fully understand.
im curious as to how the entire system works, trying to learn how to control as much as i can in command form. having fun with the terminal emulator.
just found how to clear my dalvik
$su
#cd cache/dalvik-cache
#rm *
#exit
$exit
REBOOT
im just trying to bolster up on all commands so i can better understand how the system works, and how i can manually operate it.
Another one.
Phone
$am start tel:xxx-xxx-xxxx
Another.
Open new mms.
$am start mms: XXX
(XXX is your contact name)
Edit:
$ am start mms:XXX-XXX-XXXX
Using a phone number in your contacts will open the message theard in your mms app if you already have a conversation with that contact

[GUIDE][HOWTO] Setup 2way-sync over WiFi using Unison

There are a lot of howtos about pulling/pushing content over wifi around. Taking adb or AirDroid may be reliable for common use, but i was looking for a real two-way-sync without utilizing a cloud, also i wanted not too much 3rd Party-Software involved, neither on my box nor at my phone.
Although Unison is platform-independant and can be run from Windows, i'm focussing on the Linux part (coz i've got no Windows box to test). I won't go deeper into things like howto install the required applications on your box. You won't have to compile anything, precompiled binaries should be available for your distro. Guess pacman, yum and apt-get will do their job, but if in doubt, Google will lead the way.
Requirements
A rooted device
SSHDroid installed on your Android
OpenSSH, SSHFS and Unison properly installed on your Box
SSH
After ensured the requirements above, you should be able to ssh to your android device. It's ip is shown by SSHDroid.
Code:
ssh [email protected]<yourdeviceip>
First connect will take some time, coz ssh will handshake your device and save the fingerprint. After the connect succeeded, you will be easily able to connect your device anytime over wifi.
SSHFS
SSHFS allows us to mount the whole android device to a mountpoint on your box. Compare it like a external harddisk you plug into your box usb.
First we'll create a directory in our home and then mount the device into it.
Code:
mkdir wifidroid && sshfs [email protected]<your device ip>:/sdcard/ ~/wifidroid/
SSHFS will ask for your root password anytime you try to connect. If not configured different within SSHDroid, it will be admin. You're ought to change it for safety reasons. After above steps, your device is mounted into wifidroid. You can easily browse the contents using your preferred linux filemanager (like dolphin or nautilus). To unmount device, use fusermount -u ~/wifidroid/ later.
UNISON
Unison will handle the syncing between your box and your device. It comes with an cli and even with a gui. Whatever you will use is up to your personal preference.
First of all we're going to create the unison profile directory and a basic example profile for syncing pictures.
Code:
mkdir ~/.unison && touch pictures.prf
Open pictures.prf with your preferred editor (nano, vi, kate, gedit, orwutevah) and write down some config stuff.
Code:
root=/home/<username>/Pictures
root=/home/<username>/wifidroid/Pictures
path=Friends
path=Landscape
path=Misc Stuff
perms=0
ignore=Name .*~
ignore=Name *~
ignore=Name .*
The first root=/home/<username>/Pictures points to your local pictures directory, whereas the second one, root=/home/<username>/wifidroid/Pictures points to the pictures-folder at your mounted android device. Unison syncs recursevly, so it would simply sync anything beneath the directory Pictures. If you want to sync only some Subfolders, use path=Friends i. e. to include Pictures/Friends. You may edit this to your own convince. We don't want unison to set permissions on synced files, so we set perms=0. Rest should be self explanatory.
Okay, now just fire up unison with unison pictures for cli-version, or unison-gtk pictures for the gui-version and syncing should begin.
Keep in mind that, depending on your wifi speed, it will take a huge amount of time to sync a whole mp3/picture library for the first time. After first sync things should be butter smooth
Above example is just a basic profile. You can easily use unison to backup your whole device, or, as i do, make regular backups of your Camera-Roll, WhatsApp and Threema Backups. If you wanna go deeper into this, you should take a look at the Unison Reference Guide.
Genericxx said:
There are a lot of howtos about pulling/pushing content over wifi around. Taking adb or AirDroid may be reliable for common use, but i was looking for a real two-way-sync without utilizing a cloud, also i wanted not too much 3rd Party-Software involved, neither on my box nor at my phone.
Although Unison is platform-independant and can be run from Windows, i'm focussing on the Linux part (coz i've got no Windows box to test). I won't go deeper into things like howto install the required applications on your box. You won't have to compile anything, precompiled binaries should be available for your distro. Guess pacman, yum and apt-get will do their job, but if in doubt, Google will lead the way.
Requirements
A rooted device
SSHDroid installed on your Android
OpenSSH, SSHFS and Unison properly installed on your Box
SSH
After ensured the requirements above, you should be able to ssh to your android device. It's ip is shown by SSHDroid.
Code:
ssh [email protected]<yourdeviceip>
First connect will take some time, coz ssh will handshake your device and save the fingerprint. After the connect succeeded, you will be easily able to connect your device anytime over wifi.
SSHFS
SSHFS allows us to mount the whole android device to a mountpoint on your box. Compare it like a external harddisk you plug into your box usb.
First we'll create a directory in our home and then mount the device into it.
Code:
mkdir wifidroid && sshfs [email protected]<your device ip>:/sdcard/ ~/wifidroid/
SSHFS will ask for your root password anytime you try to connect. If not configured different within SSHDroid, it will be admin. You're ought to change it for safety reasons. After above steps, your device is mounted into wifidroid. You can easily browse the contents using your preferred linux filemanager (like dolphin or nautilus). To unmount device, use fusermount -u ~/wifidroid/ later.
UNISON
Unison will handle the syncing between your box and your device. It comes with an cli and even with a gui. Whatever you will use is up to your personal preference.
First of all we're going to create the unison profile directory and a basic example profile for syncing pictures.
Code:
mkdir ~/.unison && touch pictures.prf
Open pictures.prf with your preferred editor (nano, vi, kate, gedit, orwutevah) and write down some config stuff.
Code:
root=/home/<username>/Pictures
root=/home/<username>/wifidroid/Pictures
path=Friends
path=Landscape
path=Misc Stuff
perms=0
ignore=Name .*~
ignore=Name *~
ignore=Name .*
The first root=/home/<username>/Pictures points to your local pictures directory, whereas the second one, root=/home/<username>/wifidroid/Pictures points to the pictures-folder at your mounted android device. Unison syncs recursevly, so it would simply sync anything beneath the directory Pictures. If you want to sync only some Subfolders, use path=Friends i. e. to include Pictures/Friends. You may edit this to your own convince. We don't want unison to set permissions on synced files, so we set perms=0. Rest should be self explanatory.
Okay, now just fire up unison with unison pictures for cli-version, or unison-gtk pictures for the gui-version and syncing should begin.
Keep in mind that, depending on your wifi speed, it will take a huge amount of time to sync a whole mp3/picture library for the first time. After first sync things should be butter smooth
Above example is just a basic profile. You can easily use unison to backup your whole device, or, as i do, make regular backups of your Camera-Roll, WhatsApp and Threema Backups. If you wanna go deeper into this, you should take a look at the Unison Reference Guide.
Click to expand...
Click to collapse
Thanks will try
Nice job mate. I will try it.
Thanks @Genericxx, it looks complicated at first, but after reading a while it makes complete sense,
For anyone who wants an easier way for syncing between PC windows and Android, i'd recommend ES File Explorer and Goodsync (on windows PC)
First enable FTP Remote manager in ES through a WiFi same with ur PC windows. Then open Goodsync and setup a sync wizard and choose FTP and then the ip address from ES on the Right (destination)sync folder.
It works great on the Note 2 and it is awesome app! 5 star on market and thanks here.
No need to be root
Great guide, thanks a lot!
I have two things to add.
1. You do not need to root your Android device to use SSHDroid.
2. As the user of a non-rooted device, I ran into the problem of permissions when using unison. The solution:
Apart from having the
perms = 0
line in your .prf file, also add
dontchmod = true
So, my file looks like this:
Code:
perms=0
dontchmod = true
root=/home/<username>/Pictures
root=/home/<username>/wifidroid/Pictures
ignore=Name .*~
ignore=Name *~
ignore=Name .*
Placing "perms=0" and "dontchmod = true" at the beginning of the file may be important (I read it somewhere), but maybe it is not.
And it works nicely with my non-rooted device. Thanks again!
Check also UnisonSync:
https://play.google.com/store/apps/details?id=net.danielroggen.unisonsync
It's a Unison client for Android with GUI.
The advantage of unison client (rather than server) on the answer Android device is that you can connect to your server even if your shoe Android device is on a different subnet or behind a firewall (as long as your server is accessible of course).
Cheers,
D.

Categories

Resources