Create new ssh user account to access specific folder only
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
3
down vote
favorite
I have an apache2 server running on ubuntu 16.04, for now everytime i access my project files inside a specific folder i use root user for running php function and edit some files, after i finish i need to run chown -R www-data:www-data .
inside a terminal, because after i run my php function the file owner will become user:user (root:root). what i need is:
- Create new user for my server
- When access my server using ssh this user will be inside a specific folder automatically
- Grant this user a permission to do anything inside this specific folder
For example, Create a user named tonya, when someone access server using user tonya ssh sonya@server.com
, he will be redirected to /var/www/specific_folder, user tonya can do anything inside this folder and when tonya set the php file owner or folder to tonya:www-data
it will work like when i set the file owner to www-data:www-data
server permissions ssh apache2 php
add a comment |Â
up vote
3
down vote
favorite
I have an apache2 server running on ubuntu 16.04, for now everytime i access my project files inside a specific folder i use root user for running php function and edit some files, after i finish i need to run chown -R www-data:www-data .
inside a terminal, because after i run my php function the file owner will become user:user (root:root). what i need is:
- Create new user for my server
- When access my server using ssh this user will be inside a specific folder automatically
- Grant this user a permission to do anything inside this specific folder
For example, Create a user named tonya, when someone access server using user tonya ssh sonya@server.com
, he will be redirected to /var/www/specific_folder, user tonya can do anything inside this folder and when tonya set the php file owner or folder to tonya:www-data
it will work like when i set the file owner to www-data:www-data
server permissions ssh apache2 php
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have an apache2 server running on ubuntu 16.04, for now everytime i access my project files inside a specific folder i use root user for running php function and edit some files, after i finish i need to run chown -R www-data:www-data .
inside a terminal, because after i run my php function the file owner will become user:user (root:root). what i need is:
- Create new user for my server
- When access my server using ssh this user will be inside a specific folder automatically
- Grant this user a permission to do anything inside this specific folder
For example, Create a user named tonya, when someone access server using user tonya ssh sonya@server.com
, he will be redirected to /var/www/specific_folder, user tonya can do anything inside this folder and when tonya set the php file owner or folder to tonya:www-data
it will work like when i set the file owner to www-data:www-data
server permissions ssh apache2 php
I have an apache2 server running on ubuntu 16.04, for now everytime i access my project files inside a specific folder i use root user for running php function and edit some files, after i finish i need to run chown -R www-data:www-data .
inside a terminal, because after i run my php function the file owner will become user:user (root:root). what i need is:
- Create new user for my server
- When access my server using ssh this user will be inside a specific folder automatically
- Grant this user a permission to do anything inside this specific folder
For example, Create a user named tonya, when someone access server using user tonya ssh sonya@server.com
, he will be redirected to /var/www/specific_folder, user tonya can do anything inside this folder and when tonya set the php file owner or folder to tonya:www-data
it will work like when i set the file owner to www-data:www-data
server permissions ssh apache2 php
server permissions ssh apache2 php
edited Mar 9 at 2:56
asked Mar 9 at 2:42
simple guy
1215
1215
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02
add a comment |Â
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
You should be able to accomplish this with
adduser --home /var/www/specific_folder --shell /bin/bash --no-create-home --ingroup www-data --ingroup ssh tonya
adduser
is used to add a user--home
specifies home directory which is where the user will be when they log in--shell
is to specify the shell, by default it is usually just/bin/sh
which is not as user friendly as/bin/bash
--no-create-home
will not create the home directory so you must use one that already exists--ingroup
adds the user to specified groupthe last argument is the username
You could make the user jailed using this guide:
- Restrict SSH User Access to Certain Directory Using Chrooted Jail
Please remember that even if you jail a user, it is very possible to escape a jail. If you're giving a user access to your system, you may as well be giving them root access because once they have shell access, it's almost always possible to gain root. Setting up a jail will most likely keep a basic user from doing anything too harmful but will do little to nothing to stop a malicious user from doing harmful stuff.
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You should be able to accomplish this with
adduser --home /var/www/specific_folder --shell /bin/bash --no-create-home --ingroup www-data --ingroup ssh tonya
adduser
is used to add a user--home
specifies home directory which is where the user will be when they log in--shell
is to specify the shell, by default it is usually just/bin/sh
which is not as user friendly as/bin/bash
--no-create-home
will not create the home directory so you must use one that already exists--ingroup
adds the user to specified groupthe last argument is the username
You could make the user jailed using this guide:
- Restrict SSH User Access to Certain Directory Using Chrooted Jail
Please remember that even if you jail a user, it is very possible to escape a jail. If you're giving a user access to your system, you may as well be giving them root access because once they have shell access, it's almost always possible to gain root. Setting up a jail will most likely keep a basic user from doing anything too harmful but will do little to nothing to stop a malicious user from doing harmful stuff.
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
add a comment |Â
up vote
3
down vote
accepted
You should be able to accomplish this with
adduser --home /var/www/specific_folder --shell /bin/bash --no-create-home --ingroup www-data --ingroup ssh tonya
adduser
is used to add a user--home
specifies home directory which is where the user will be when they log in--shell
is to specify the shell, by default it is usually just/bin/sh
which is not as user friendly as/bin/bash
--no-create-home
will not create the home directory so you must use one that already exists--ingroup
adds the user to specified groupthe last argument is the username
You could make the user jailed using this guide:
- Restrict SSH User Access to Certain Directory Using Chrooted Jail
Please remember that even if you jail a user, it is very possible to escape a jail. If you're giving a user access to your system, you may as well be giving them root access because once they have shell access, it's almost always possible to gain root. Setting up a jail will most likely keep a basic user from doing anything too harmful but will do little to nothing to stop a malicious user from doing harmful stuff.
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You should be able to accomplish this with
adduser --home /var/www/specific_folder --shell /bin/bash --no-create-home --ingroup www-data --ingroup ssh tonya
adduser
is used to add a user--home
specifies home directory which is where the user will be when they log in--shell
is to specify the shell, by default it is usually just/bin/sh
which is not as user friendly as/bin/bash
--no-create-home
will not create the home directory so you must use one that already exists--ingroup
adds the user to specified groupthe last argument is the username
You could make the user jailed using this guide:
- Restrict SSH User Access to Certain Directory Using Chrooted Jail
Please remember that even if you jail a user, it is very possible to escape a jail. If you're giving a user access to your system, you may as well be giving them root access because once they have shell access, it's almost always possible to gain root. Setting up a jail will most likely keep a basic user from doing anything too harmful but will do little to nothing to stop a malicious user from doing harmful stuff.
You should be able to accomplish this with
adduser --home /var/www/specific_folder --shell /bin/bash --no-create-home --ingroup www-data --ingroup ssh tonya
adduser
is used to add a user--home
specifies home directory which is where the user will be when they log in--shell
is to specify the shell, by default it is usually just/bin/sh
which is not as user friendly as/bin/bash
--no-create-home
will not create the home directory so you must use one that already exists--ingroup
adds the user to specified groupthe last argument is the username
You could make the user jailed using this guide:
- Restrict SSH User Access to Certain Directory Using Chrooted Jail
Please remember that even if you jail a user, it is very possible to escape a jail. If you're giving a user access to your system, you may as well be giving them root access because once they have shell access, it's almost always possible to gain root. Setting up a jail will most likely keep a basic user from doing anything too harmful but will do little to nothing to stop a malicious user from doing harmful stuff.
edited Mar 10 at 7:46
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12.3k52256
12.3k52256
answered Mar 9 at 2:47
![](https://lh4.googleusercontent.com/-Ff7UEvtYtuM/AAAAAAAAAAI/AAAAAAAAC8k/dFgDKu0BHCw/photo.jpg?sz=32)
![](https://lh4.googleusercontent.com/-Ff7UEvtYtuM/AAAAAAAAAAI/AAAAAAAAC8k/dFgDKu0BHCw/photo.jpg?sz=32)
Desultory
1113
1113
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
add a comment |Â
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
why there's 2 ingroup? how can this user get my root access?
â simple guy
Mar 9 at 4:17
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
one ingroup for ssh and one for www-data, and I'm not saying that they will be able to get root access but you should never allow a user on your system if you don't trust them because once they have shell access on your system, they're 50% the way to root basically. New exploits are discovered daily and because of that, you can never consider a system to be secure.
â Desultory
Mar 9 at 15:48
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
@Desultroy when i change my php file owner from www-data:www-data to tonya:www-data it gives me a file permission error , when i try to access the php from browser
â simple guy
Mar 14 at 6:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
You should probably change the permissions of the file so that it is group based and not owner based. I don't know if php requires the execute permission but it definitely needs the read permission. Permissions can be explained here: help.ubuntu.com/community/FilePermissions
â Desultory
Mar 15 at 0:41
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013286%2fcreate-new-ssh-user-account-to-access-specific-folder-only%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
See also askubuntu.com/questions/46331/â¦
â Panther
Mar 9 at 5:02