# su single command?



## sentofuno (Dec 22, 2009)

hi all, i'm new to FreeBSD and need something clarifying. i tried googling and the documentation but i'm still not quite sure on something

i am used to running commands in linux with elevated privileges like this:


```
sudo command filename.ext
```

eg


```
sudo edit textfile.txt
```


with FreeBSD i don't seem to be able to run single commands like that. i have added my account to the wheel group, and i can 'su' to the root environment from my account but trying to run:


```
su pkg_add -r xorg
```

results in 'bad su, su sorry' etc. 

if i understand it correctly 'su'-ing is inadvisable as it leaves me in a root user state, and as i read at http://www.manpages.info/freebsd/su.1.htmlhere can affect user variables, so i am making changes to the root account rather than my own

so is there a way to run single commands like in my example?

thanks in advance


----------



## DutchDaemon (Dec 22, 2009)

If you're used to sudo, install sudo from ports (security/sudo). You normally don't run 'su' in a command, but as a way to get to the root shell (`$ su` [enter], password, or `$ su -`, [enter], password) and perform commands there.


----------



## mickey (Dec 22, 2009)

Just install security/sudo and work with sudo as you are used to.


----------



## aragon (Dec 22, 2009)

Try


```
su root -c 'id'
```


----------



## graudeejs (Dec 22, 2009)

to use su, you need to use quote for it's argument, that you want to execute, if it has parameteres
for example, I run
`$ su -m root -c mksh`
or
`$ su -m root -c 'portsnap fetch update'`


----------



## sentofuno (Dec 22, 2009)

killasmurf86, worked perfectly - thank you. 

thanks to everyone else who replied, i have installed sudo for later but will use killasmurf86's suggestion for now. i've been using FreeBSD for less than 10 hours now (aside from some use of pfSense and m0n0wall) and to begin with i would like to do things the 'FreeBSD' or 'native' way. 



the whole point of my trying FreeBSD was to understand and choose every command i run, and program i open. so far i'm very impressed. i have only installed x11 for a GUI but its enough to launch GUI apps like firefox, thunderbird etc from xterm windows. the mix of CLI and GUI suits me very well.


----------



## Deleted member 9563 (Dec 23, 2009)

I'm also new and ran up against the same "problem", but since there are all these "terminals" available, I found that just leaving the one I'm in and logging in as root on another one works really well.


----------



## graudeejs (Dec 23, 2009)

OJ said:
			
		

> I'm also new and ran up against the same "problem", but since there are all these "terminals" available, I found that just leaving the one I'm in and logging in as root on another one works really well.



tried sysutils/tmux or sysutils/screen already?


----------



## Deleted member 9563 (Dec 23, 2009)

killasmurf86 said:
			
		

> tried sysutils/tmux or sysutils/screen already?


Boy, you really want me to try those eh? OK, I'll get tmux right away and see how that goes.


----------



## graudeejs (Dec 23, 2009)

OJ said:
			
		

> Boy, you really want me to try those eh? OK, I'll get tmux right away and see how that goes.



you may wanna try my ~/.tmux.conf

```
set-option -g prefix C-b
set-option -g default-path $HOME
set-option -g set-titles on
set-option -g status-keys vi

set-window-option -g utf8 on

bind-key C-s choose-session
bind-key C-w choose-window
bind-key C-k kill-session
```


----------



## Deleted member 9563 (Dec 23, 2009)

Thanks, I loaded that. However, there's a bit of a learning curve here, and I'm a bit slow.  I see that the Ctrl-Alt-Fx still works. That means I can have terminals running in two dimensions. I like that. That's what I do with my windows in KDE instead of that stupid minimize thing that Microsoft people do. Anyway, I'll be working on the tmux for a while, but it's looking good!


----------



## phoenix (Dec 23, 2009)

The benefit of using tmux is that you can start tmux on a local console, open a bunch of virtual screens inside tmux (CTRL+B,C to create, CTRL+B,N to switch to the next one, CTRL+B,P to switch to previous one), then detach the tmux sessions (CTRL+B,D) and logout of the box.  Later, you can SSH into the box, and run *tmux attach* and have it reconnect to the running tmux session, with all your screens loaded and your apps running.

Where it gets even better is if you connect via SSH initially, and start tmux, and do everything in there.  If your SSH connection dies for whatever reason, none of your running apps or sessions are interrupted.  Just reconnect via SSH, and attach to the running tmux session.

Once you start using tmux, especially via SSH, you'll find it very hard to work on a system without it.


----------



## graudeejs (Dec 23, 2009)

screen does the same, except that It use C-A.... combinations and is GPL licensed instead of bsd


----------



## Aprogas (Dec 25, 2009)

Does tmux support multisession? i.e. multiple SSH connections that resume the same tmux session


----------



## graudeejs (Dec 25, 2009)

yes, it does


----------



## phoenix (Dec 27, 2009)

It even supports multiple simultaneous connections to the same tmux session.  I often leave tmux running on my work computer, and connect to it from home, and it's still running in Konsole when I get back to work.  No detach required.


----------

